我使用下面的代码来上传和调整多个图像的大小。
如果我选择大约10-20个图像,一切正常,但如果我选择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");
}
}
}
}
答案 0 :(得分:1)
在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中的更新更改,然后上传图像,如果再次出现问题,则将此值增加到更大。
答案 1 :(得分:0)
最大文件大小限制为128兆字节(或可根据要求进行更改)。 在变量
下检查php.iniupload_max_filesize = **
post_max_size = **