0

我想上传多张图片。img[]包含所有要上传的图像文件。这些值已成功插入到内爆的数据库中commas(,)。但是图像没有上传到名为 . 的指定文件夹photos中。

<input type="file" name="img[]" id="img[]" />


$n=$_FILES["img"]["name"];
$t=$_FILES["img"]["tmp_name"];
$image=implode(",",$n);


             $ex=explode(",",$image);
         $i=0;
         foreach($ex as $item)
         {

             move_uploaded_file($_FILES["img[$i]"]["tmp_name"],"photos/$ex[$i]");

             $i++;
         }
4

1 回答 1

0

我认为您的正确代码应该是

<input type="file" name="img[]" id="img[]" />


$n=$_FILES["img"]["name"];
$t=$_FILES["img"]["tmp_name"];
$image=implode(",",$n);

 // no need to explode here

     foreach($n as $key=>$item)
     {
         //name will be there in $items 
        // use temp_name of same file for which you are using name using $_FILES["img"]["tmp_name"][$key]
         move_uploaded_file($_FILES["img"]["tmp_name"][$key],"photos/$item");
     }
于 2013-04-01T09:46:43.967 回答