2012-03-04 83 views
0

我有一个简单的表单,其中Uploadify字段允许多个图像上传。但是,当我选择我的文件(并将它们添加到队列中)时,它似乎没有做任何事情,并且在控制台中没有输出。将文件添加到队列后,Uploadify不执行任何操作

这里是我的HTML:

<script> 
    $(function() { 
     $('#file_upload').uploadify({ 
      uploader: '/cms/tpl/swf/uploadify.swf', 
      script: '/cms/inc/upload_image.php?album=39', 
      cancelImg: '/cms/tpl/img/cross.gif', 
      folder: '/tpl/uploads', 
      multi: true, 
      auto: true, 
      fileExt: '*.jpg;*.gif;*.png', 
      fileDesc: 'Image files (.jpg, .gif, .png)', 
      queueID: 'file_queue', 
      queueSizeLimit: 10, 
      simUploadLimit: 10, 
      sizeLimit: 1048576, 
      removeCompleted: false, 
      scriptData: { 
       'album': '39', 
       'session': 'aeac944c4e911edc5e5de10c98b8e5b7' 
      }, 
      onError: function(a,b,c,d) { 
       console.log(a); 
       console.log(b); 
       console.log(c); 
       console.log(d); 
      }, 
      onSelectOnce: function(event,data) { 
       $('#status_message').text(data.filesSelected + ' files have been added to the queue.'); 
      }, 
      onComplete: function(a,b,c,d,e) { 
       if (d !== '1') { 
        alert(d); 
       } 
       else { 
        alert('Filename: ' + c.name + ' was uploaded'); 
       } 
      }, 
      onAllComplete: function(event, data) { 
       $('#status_message').text(data.filesUploaded + ' files uploaded; ' + data.errors + ' errors.'); 
      } 
     }); 
    }); 
</script> 

这里是我用来处理文件上传的服务器端脚本(PHP):

<?php 
/** 
* @todo Validation! 
*/ 

if (isset($_POST) && isset($_FILES['Filedata'])) { 

    $upload_dir = '../../tpl/uploads/'; 

    $source = $_FILES['Filedata']['tmp_name']; 
    $filename = sprintf('%s.%s', uniqid(), $mime[$_FILES['Filedata']['type'][$name.'_upload']]); 
    $destination = $this->uploads_dir.$filename; 

    require '../../inc/database.php'; 
    require '../../inc/globals.php'; 

    if (move_uploaded_file($source, $destination)) { 
     try { 
      $sql = "INSERT INTO gallery_images (album, image) VALUES (?,?)"; 
      $smt = $pdo->prepare($sql); 
      $res = $smt->execute(array($_REQUEST['album'], $filename)); 
     } 
     catch (PDOException $e) { 
      // send error message 
     } 
    } 

    switch ($_FILES['Filedata']['error']) { 
     case 0: 
      // $msg = 'File successfully uploaded'; 
     break; 
     case 1: 
     case 2: 
      $msg = 'File size exceeds limit'; 
     break; 
     case 3: 
      $msg = 'The file was only partially uploaded'; 
     break; 
     case 4: 
      $msg = 'No file was specified'; 
     break; 
     case 6: 
      $msg = 'The temporary folder could not be found'; 
     break; 
     case 7: 
      $msg = 'Failed to write the file to disk'; 
     break; 
     case 8: 
      $msg = 'File upload stopped by extension'; 
     break; 
     default: 
      $msg = 'Unknown error'; 
     break; 
    } 

    if ($msg) { 
     $stringData = "Error: ".$_FILES['userfile']['error']." Error Info: ".$msg; 
    } 
    else { 
     $stringData = "1"; // This is required for onComplete to fire on Mac OSX 
    } 

    echo $stringData; 
} 

十分简陋,但做这项工作。难道我做错了什么?有什么我错过了吗?在查看Uploadify演示页面后,上面的内容放在一起。

回答

0

我想,你可能会使用jQuery.noConflict()方法不是吗?我有一个类似的问题,我的文件没有事件最终在文件队列...也没有输出到控制台... 我怀疑jQuery.noConflict ...在我的情况...也许我的心态可能会帮助你:)

+0

不,我不认为这会是。我没有使用'jQuert.noConflict();',我没有在我的页面上使用任何其他JavaScript库。 – 2012-04-04 11:24:56

相关问题