doufan3408 2017-10-23 22:55
浏览 24
已采纳

当我选择许多图像时,Php多图像上传失败

I use this code below, to upload and resize multiple images.

If i select about 10-20 image, everything works fine, but if i select 50 or more images, nothing happens, the page just reloads after a few seconds.

The code has some problem, or the max file size is limited in the ini file or server config?

enter image description here

enter image description here

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");
            }
        }
    }
}

展开全部

  • 写回答

2条回答 默认 最新

  • duanjiao6730 2017-10-24 00:07
    关注

    Update this settings in your 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
    

    and then restart your server, check for updated changes in php.ini through browser and then upload images, if again you getting issue then increse this values to larger.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 centos7.6进不去系统,卡在数字7界面
  • ¥15 Tensorflow采用interpreter.allocate_tensors()分配内存出现ValueError: vector too long报错
  • ¥15 使用CGenFF在线生成血红素辅基拓扑结构遇到问题
  • ¥15 在fragment使用okhttp同步上传文件,能不能在fragment销毁后还可以继续上传文件?
  • ¥20 matlab代码实现可达矩阵形成骨骼矩阵
  • ¥15 关于地板的木纹和图库中的匹配的
  • ¥30 机器学习预测疾病模型流程疑问
  • ¥50 2048Python实现
  • ¥15 使用ads进行低噪放仿真没有结果且不报错
  • ¥15 关于#python#的问题:有偿求一个千寻框架找书机器人插件
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部