1

我的网站上有两种表格,一种上传单个文件,另一种上传多个文件。两种形式都上传到同一个目录,并且单个文件形式可以完美地工作。为了优化多文件上传表单的代码,以便我不会单独写出每个文件的处理,我有以下代码:

foreach($_FILES['multi']['name'] as $uploaded_file){
     if(!move_uploaded_file($uploaded_file, "/var/www/uploads/".$uploaded_file."")){
         echo "Could not move File: ".$uploaded_file."<br />";
     }else{
         // Do additional processing
     }  
}

脚本没有将文件移动到有效且适用于单个文件上传表单的目录,而是出错并显示我的停止消息:

"Could not move File: <filename here>"

一直在挠头,非常感谢任何见解和帮助!

4

2 回答 2

1

您没有正确定位上传的临时文件位置:

foreach ($_FILES['multi']['name'] as $idx => $uploaded_file) {
    move_uploaded_file($_FILES['multi']['tmp_name'][$idx], "/var/www/uploads/$uploaded_file");
}
于 2012-11-29T03:30:16.943 回答
0

尝试类似:

$count=0; 
foreach($_FILES['multi']['name'] as $uploaded_file) {
   $tmp=$_FILES['file']['tmp_name'][$count];
   if(!move_uploaded_file($tmp, "/var/www/uploads/".$uploaded_file)){
     echo "Could not move File: ".$uploaded_file."<br />";
   }else{
     // Do additional processing
   }   
   $count=$count + 1;
}
于 2012-11-29T03:24:13.647 回答