2012-03-04 86 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

相關問題