【发布时间】:2011-03-08 16:45:28
【问题描述】:
我希望我能给你一个链接,但上次他们把这一切都归咎于我,所以这里是 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 是查看我的故事的链接
【问题讨论】:
-
var_dump( $_FILES )提供了什么? -
能否在上传脚本中显示
var_dump($_FILES);运行的结果? -
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) "application/octet-stream" [2]=> string(24) "application/octet-stream" } ["tmp_name"]=> array(3) { [0]=> string(0) "" [1]=> 字符串(14) "/tmp/php3NXUyj" [2]=> 字符串(14) "/tmp/phpbBVhSj" } ["错误"]=> 数组(3) { [0]=> int(4) [1]=> int(0) [2]=> int(0) } ["size"]=> array(3) { [0]=> int(0) [1]=> int (0) [2]=> int(916) } } } 阴影
-
foreach($_FILES['file']['name'] as $file) { echo $file; } /*这东西有效,但为什么不是以前的它对我来说仍然是个谜*/
-
自己解决了。这是因为每次选择新文件时 insertBefore() 都会将新的“空”输入元素放在第一个 [0] 位置。谢谢大家!
标签: php javascript html upload