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