Php 当我 select 多张图片时,多张图片上传失败

Php multiple image upload fails when i select many images

我使用下面的代码上传多张图片并调整其大小。

如果我 select 大约 10-20 张图片,一切正常,但如果我 select 50 张或更多图片,什么也不会发生,页面会在几秒钟后重新加载。

代码有问题,或者 ini 文件或服务器配置中限制了最大文件大小?

if(isset($_POST['submit']))
{
    if(isset($_FILES['gallery']))
    {
        foreach($_FILES['gallery']["name"] AS $key=>$file)
        {
            if($_FILES['gallery']['size'][$key]  != 0 )
            {
                $ThumbSquareSize        = $gallery_thumb_size;
                $BigImageMaxSize        = $gallery_big_size;
                $ThumbPrefix            = "th-";
                $DestinationDirectory   = '../images/gallery/';
                $Quality                = $imgQuality;
                if(!is_uploaded_file($_FILES['gallery']['tmp_name'][$key]))
                {
                    $error[] = "Elképzelhető, hogy nem választott ki fényképet.";
                }

                $RandomNumber   = $id.'-'.rand(0, 99999999);

                $ImageName      = str_replace(' ','-',strtolower($_FILES['gallery']['name'][$key]));
                $ImageSize      = $_FILES['gallery']['size'][$key] ;
                $TempSrc        =   $_FILES['gallery']['tmp_name'][$key];
                $ImageType      =   $_FILES['gallery']['type'][$key];
                switch(strtolower($ImageType))
                {
                    case 'image/png':
                        $CreatedImage =  imagecreatefrompng($_FILES['gallery']['tmp_name'][$key] );
                        break;
                    case 'image/gif':
                        $CreatedImage =  imagecreatefromgif($_FILES['gallery']['tmp_name'][$key]);
                        break;
                    case 'image/jpeg':
                    case 'image/pjpeg':
                        $CreatedImage = imagecreatefromjpeg(  $_FILES['gallery']['tmp_name'][$key]);
                        break;
                    default:
                    $error[] = "Nem támogatott fájlformátum.";
                }
                list($CurWidth,$CurHeight)=getimagesize($TempSrc);
                $ImageExt = substr($ImageName, strrpos($ImageName, '.'));
                $ImageExt = str_replace('.','',$ImageExt);
                $ImageName      = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName);
                $NewImageName = $ImageName.'-'.$RandomNumber.'.'.$ImageExt;
                $thumb_DestRandImageName    = $DestinationDirectory.$ThumbPrefix.$NewImageName;
                $DestRandImageName          = $DestinationDirectory.$NewImageName;
                if(!resizeImage($CurWidth,$CurHeight,$BigImageMaxSize,$DestRandImageName,$CreatedImage,$Quality,$ImageType))
                {
                    $error[] = "A fénykép átméretezése nem sikerült.";

                }
                if(!cropImage($CurWidth,$CurHeight,$ThumbSquareSize,$thumb_DestRandImageName,$CreatedImage,$Quality,$ImageType))
                {
                    $error[] = "Nem sikerült a bélyegkép készítése.";
                }

                //$gallery_text = mysqli_real_escape_string($kapcs,  $_POST["images_alt"][ $key ] );
                $gallery_text = "";
                $gallery_thumb = basename( $thumb_DestRandImageName );
                $gallery_big = basename($DestRandImageName);
                $gallery_insert = "INSERT INTO gallery_item SET gallery_item_nev = '$gallery_text', gallery_item_thumb = '$gallery_thumb', gallery_item_big = '$gallery_big', gallery_id = '$id'";
                mysqli_query($kapcs , $gallery_insert ) or die( mysqli_error());
                header("Location: ".$host."/".$admin_folder."/galeria-szerkesztes.php?id=".$id."&new=1");
            }
        }
    }
}

最大文件大小限制为 128 兆字节(或者可以根据要求进行更改)。 在变量

下签入 php.ini
upload_max_filesize = **
post_max_size = **

在您的 php.ini

中更新此设置
memory_limit = 256M
upload_max_size = 64M
post_max_size = 64M
upload_max_filesize = 64M
max_execution_time = 300
max_input_time = 1000

然后重新启动您的服务器,通过浏览器检查 php.ini 中的更新更改,然后上传图像,如果您再次遇到问题,则将此值增加到更大。