PHP多个文件上传和创建缩略图,每个循环都无法进入


PHP Multiple file upload and create thumbnails not getting into for each loop

这是我到目前为止所拥有的,我为长度道歉,但这给了你完整的画面:

if(count($_FILES['file']['name'])) 
            {
            foreach ($_FILES['file']['name'] as $key => $file)
                {

            $add="../uploads/photogallery/".time().'_'.$file;
            $storefile = time().'_'.$file;
                             echo $storefile; // THIS WORKS
                if(move_uploaded_file ($_FILES['file']['tmp_name'][$key],$add))
                {
                                     // CODE IS NOT GETTING INTO THIS AREA,
                    //database insert here
                    //mysql_query ($query);
                    echo '<meta http-equiv="refresh" content="0;url=?VIEW=PHOTOADD&photo_added">';
                }
                else
                {
                    echo '<meta http-equiv="refresh" content="0;url=?VIEW=PHOTOADD&photo_not_added">';
                }
            ///////// Start the thumbnail generation//////////////
            $n_width=150;          // Fix the width of the thumb nail images
            $n_height=150;         // Fix the height of the thumb nail imaage
            $tsrc="../uploads/photogallery/thumbnail/".time().'_'.$file;
            if (!($_FILES['file']['type'][$key] =="image/pjpeg" || $_FILES['file']['type'][$key] == "image/gif" || $_FILES['file']['type'][$key] == "image/png") || ($_FILES["file"]["type"][$key] == "image/jpeg") && ($_FILES["file"]["size"][$key] < 2097152))
                {
                    echo '<meta http-equiv="refresh" content="0;url=?VIEW=PHOTOADD&photo_requirements_not_met">';
                }
            /////////////////////////////////////////////// Starting of GIF thumb nail creation///////////
            if (@$_FILES['file']['type'][$key] =="image/gif")
                {
                    $im=ImageCreateFromGIF($add);
                    $width=ImageSx($im);              // Original picture width is stored
                    $height=ImageSy($im);                  // Original picture height is stored
                    $newimage=imagecreatetruecolor($n_width,$n_height);
                    imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
                    if (function_exists("imagegif")) 
                    {
                        Header("Content-type: image/gif");
                        ImageGIF($newimage,$tsrc);
                    }
                    elseif (function_exists("imagejpeg")) 
                    {
                        Header("Content-type: image/jpeg");
                        ImageJPEG($newimage,$tsrc);
                    }
                    elseif (function_exists("imagepng")) 
                    {
                        Header("Content-type: image/png");
                        ImagePNG($newimage,$tsrc);
                    }
                }
            ////////////// starting of JPG thumb nail creation//////////
            if ($_FILES['file']['type'][$key] == "image/pjpeg")
                {
                    $im=ImageCreateFromJPEG($add); 
                    $width=ImageSx($im);              // Original picture width is stored
                    $height=ImageSy($im);             // Original picture height is stored
                    $newimage=imagecreatetruecolor($n_width,$n_height);                 
                    imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
                    ImageJpeg($newimage,$tsrc);
                }
            if ($_FILES['file']['type'][$key] == "image/png")
                {
                    $im=ImageCreateFromPNG($add); 
                    $width=ImageSx($im);              // Original picture width is stored
                    $height=ImageSy($im);             // Original picture height is stored
                    $newimage=imagecreatetruecolor($n_width,$n_height);                 
                    imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
                    ImagePNG($newimage,$tsrc);
                }
            }
        }
        else
        {
            echo '<meta http-equiv="refresh" content="0;url=?VIEW=PHOTOADD&photo_requirements_not_met">';
        }

这是表单的HTML部分:

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

是的,表单的enctype正确。请参阅我在上面代码中的评论,上面写着THIS WORKS and code IS NOT。。等等。这就是我的问题所在。它进入了for每个循环部分,因为我可以回显$storefile并获得带有时间戳的正确文件名,但它不会进入if(move_uploaded_..)部分,并跳到回显照片要求未满足部分。

如有任何帮助,我们将不胜感激。我没有得到任何PHP或mysql错误。

使用foreach ($_FILES['file']['name'] as $key => $file)作为循环

if子句中的$_FILES['file']['tmp_name'][$key]

供参考

例如,假设文件名/home/test/review.html和/home/test/xwp.out已提交。在这种情况下,$_FILES['userfile']['name'][0]将包含值review.html,$_FILES['userfile']['name']1将包含值xwp.out。类似地,$_FILES['userfile']['size'][0]将包含review.html的文件大小等等。

$_FILES['userfile']['name'][0]、$_FILES['userfile']['tmp_name'][0],$_FILES['userfile']['size'][0]和$_FILES['userfile']['type'][0]是也设置。