2011-10-05 86 views
-1

此文件索引阿賈克斯上傳錯誤

<form name="classupload" method="post" enctype="multipart/form-data" action=""> 
     <h3>Select pictures:&nbsp;</h3><br /> 
     <input type="file" name="Filedata[]" style="margin-top:2px;"/><br /> 
     <input type="file" name="Filedata[]" style="margin-top:2px;"/><br /> 

     <input type="file" name="Filedata[]" style="margin-top:2px;"/><br /> 
     <input type="file" name="Filedata[]" style="margin-top:2px;"/><br /> 
     <input type="file" name="Filedata[]" style="margin-top:2px;"/><br /> 
     <div id="viac"></div> 
     <div style="margin-top:4px;"><a onclick="multiupload();">More</a><br /></div> 
     <input type="submit" value="Upload" id="classupload"/> 
     </form> 

和文件的JavaScript

jQuery(document).ready(function() { 
$("#classupload").click(function() { 
     var xleng=document.classupload.elements['Filedata[]'].length; 
     dv = document.createElement("div"); 
     for (var i = 0; i < xleng ; i++) 
     { 
      img=document.classupload.elements['Filedata[]'][i].value; 
      if(img.toString().length > 1){ 
       $.ajax({ 
        type: "POST", 
        url: "upload.php", 
        data: img, 
        success: function(data_response) { 
         dv.innerHTML = i + ' - ' + data_response; 
        } 
       }); 
      } 
     } 
     responseStatus("Done!"); 
     document.getElementById("result").appendChild(dv); 

     return false; // avoid to execute the actual submit of the form. 


    }) 

}); 

和文件upload.php的

if ($_REQUEST['Filedata']) { 

} 

請幫我寫文件upload.php的顯示文件 因爲而不是上傳的文件,我什麼也沒得到,請幫助?

回答

1

您無法直接通過AJAX上傳文件。您需要一個使用隱藏的iframe或利用HTML5功能的插件。

+0

但其他插件使用Flash Player – Thoman

+0

根據Flash是一個壞主意。 –