2011-03-08 74 views
-1

我希望我可以给你一个链接,但他们指责这一切对我所以在这里最后一次是javascript代码:

function Multifile(list){ 
    this.id=0; 
    this.list=list; 

    this.createNew=function(element){ 
     element.name='file[]'; 
     element.multiFile=this; 

     element.onchange=function(){ 
      var newElement=document.createElement('input'); 
      newElement.type='file'; 
      this.parentNode.insertBefore(newElement,this); 
      this.multiFile.createNew(newElement); 
      this.multiFile.addList(this); 
      this.style.position='absolute'; 
      this.style.left='-1000px'; 
     }; 
    }; 

    this.addList=function(element){ 
     var newRow=document.createElement('div'); 
     var newButton=document.createElement('input'); 

     newButton.type='button'; 
     newButton.value='delete'; 
     newRow.element=element; 

     newButton.onclick=function(){ 
      this.parentNode.element.parentNode.removeChild(this.parentNode.element); 
      this.parentNode.parentNode.removeChild(this.parentNode); 
      return false; //safari thing 
     }; 

     newRow.innerHTML=element.value; 
     newRow.appendChild(newButton); 
     this.list.appendChild(newRow); 
    }; 
}; 

var multifile=new Multifile(document.getElementById('fList')); 
multifile.createNew(document.getElementById('file')); 

这是HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title></title> 
    </head> 
    <body> 
     <form id="upload" action="uploadPost.php" method="post" enctype="multipart/formdata"> 
      <input id="file" type="file"/> 
      <input type="submit" value="upload"/> 
     </form> 
     <div id="fList"> 
     </div> 
     <script type="text/javascript" src="javascriptcode.js"> 
     </script> 
    </body> 
</html> 

我的PHP脚本: '; echo $ _FILES ['file'] ['name'] 1; ? >

,并在这里结束我的问题:

选择2档它从来没有要打印数组成员后,[0] 除了当我删除第二个文件时,它给它的1到数组成员值最初有[0]

HERE数组成员值的第一个元素是要看到什么是我的故事

+0

这是什么'的var_dump($ _ FILES)'给? – 2011-03-08 16:47:25

+0

你可以显示'var_dump($ _ FILES)的结果;'在上传脚本中运行吗? – 2011-03-08 16:47:28

+0

array(1){[“file”] => array(5){[“name”] => array(3){[0] => string(0)“”[1] => string(6) “shadow”[2] => string(5)“group”} [“type”] => array(3){[0] => string(0)“”[1] => string(24)/octet-stream“[2] => string(24)”application/octet-stream“} [”tmp_name“] => array(3){[0] => string(0)”“[1] => string(14)“/ tmp/php3NXUyj”[2] => string(14)“/ tmp/phpbBVhSj”} [“error”] => array(3){[0] => int(4)[1] => int(0)[2] => int(0)} [“size”] => array(3){[0] => int(0)[1] => int > int(916)}}} shadow – daniel 2011-03-08 22:41:56

回答

5

看起来像一个错字的链接。

enctype="multipart/formdata" 

必须

enctype="multipart/form-data" 
+0

没有区别 – daniel 2011-03-08 23:49:43