上传数组内的图像不起作用

时间:2013-04-01 09:35:26

标签: php image file-upload

我想上传多张图片。 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++;
         }

1 个答案:

答案 0 :(得分: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");
     }