是的,我知道有几百个类似的问题,但我没有找到一个工作的答案... 问题是:我想上传多个文件... 正确的方法应该是这样的:PHP多个文件上传
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="?u=1">
<input type="file" name="myFile[]" />
<input type="file" name="myFile[]" />
<input type="file" name="myFile[]" />
<input type="submit" value="Upload!" name="submit"/>
</form>
<?
if ($_GET['u']){
foreach ($_FILES["myFile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["myFile"]["tmp_name"][$key];
$name = $_FILES["myFile"]["name"][$key];
// here we move it to a directory called data
// you can move it wherever you want
move_uploaded_file($tmp_name, "/data/$name");
} else {
// an error occurred, handle it here
}
}
}
if (!$_FILES){
echo 'WTF?? No files sent?? There\'s a problem! Let\' hope that stack overflow will solve it!';
}
?>
</body>
</html>
输出是:
Notice: Undefined index: myFile in C:\xampp\htdocs\php\prova.php on line 18
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\php\prova.php on line 18
没有文件发送?有问题!我怎样才能访问从数组输入标签上传的文件?
echo声明是否触发底部? – MrCode
用MAMP在我的Mac上本地运行这个工作正常,文件上传时没有任何问题。可能是你的设置,而不是代码 – Luke
它工作正常吗?我是唯一一个不工作的人? echo语句打印这个句子,但有人提出我的问题! – user1448411