Uploadify not passing variables, Session problem?

这一生的挚爱 提交于 2020-01-12 10:12:51

问题


For the love of pete I can't get it to accept any variables into to my SQL db. If I put static info it works. I can't seem to pass any paramaters over with scriptdata and it makes it more challenging because I'm using smarty template system on top.

I was trying to do this.

 {literal}
<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery("#fileUpload").uploadify({

        'scriptData'     :{'alb_id': '{/literal}$alb_id{literal}','mem_id': '{/literal}$info.mem_id{literal}'},
        'uploader': '/ajax/upload/uploadify.swf',
        'cancelImg': '/ajax/upload/cancel.png',
        'script': '/ajax/upload/uploader.php',
        'folder': 'photos',
        'multi': true,
        'displayData': 'speed',
        'fileDesc'  : 'Image Files',
        'fileExt': '*.jpg;*.jpeg;',
        'simUploadLimit': 200,
        'width'          : 130,
        'queueID'        : 'fileQueue',
        'buttonImg': '/themes/mytheme/gfx/buttons/but_browse.gif'       
    });

});
</script>
{/literal}

In my template file. The upload part works fine. Just not the mysql. I am using a function built into the script to resize images for thumbnailes and what not and build a directory. All that works. It just won't pass any variables to the db.

include_once("../../includes/config/config.inc.php");
    //load libraries
include(DOC_ROOT."/libraries.php");


$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS,1);
mysql_select_db(SQL_DB,$conn);

$alb_id = $_REQUEST['alb_id'];
$mem_id = $_REQUEST['mem_id'];  


if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];

        $extension = ".jpeg";
        $photo = build_thumbnailes($tempFile,$extension);

        $sql ="INSERT INTO `photos`(`mem_id`, `photo`, `photo_med`, `photo_small`, `approved`,`posted`, `upload_date`) 
        VALUES 
        ('$alb_id', '".$photo["ex"]."', '".$photo["med"]."','".$photo["small"]."' , '1', time(), time())";
        mysql_query($sql) or die(mysql_error());

Please help if you can. I'm going crazy with this thing. Thanks.


回答1:


Well I don't know if this is the "answer" but I do see a couple of problems.

  1. In your template you have:

    'scriptData': {'alb_id': '{/literal}$alb_id{literal}',
                   'mem_id': '{/literal}$info.mem_id{literal}'},
    

    Your smarty variables $alb_id and $info.mem_id are going to be passed literally (instead of their values). You need:

    'scriptData': {'alb_id': '{/literal}{ $alb_id }{literal}',
                   'mem_id': '{/literal}{ $info.mem_id }{literal}'},
    
  2. Secondly you should be checking if your file is truly an uploaded file in your PHP. Instead of:

    if (!empty($_FILES)) {
        $tempFile = $_FILES['Filedata']['tmp_name'];
    

    Use:

    if (is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
        $tempFile = $_FILES['Filedata']['tmp_name'];
    

I really suspect you aren't getting the data from the form you think you're getting. How do you know the upload is working? How do you know the values were passed from the form? You might want to print out the variables from the form to see if you're really getting what you expect.

Do you get an error from MySQL? Or is it that the data just doesn't show up? Providing some more info might get you some better answers here.




回答2:


A easy way to test your script is create a normal file input in a normal form wich action you point to upload.php . So if there is an error you will see it then.

Is it possible build_tumbnailes is trowing an error?




回答3:


The only thing that's necessary is to remove {literal}. Then it should work!



来源:https://stackoverflow.com/questions/3499387/uploadify-not-passing-variables-session-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!