Hi guys,
Having a problem with users uploading photos onto my site. They can upload 6 images under 5MB. The memory setting is set to 128M in my php.ini and I doubled checked by phpinfo()
upload_max_filesize = 30M ;5MBlimit*6images=30MB
post_max_size = 30M
max_execution_time = 120
max_file_uploads = 7
memory_limit=128M
However I get the error message occasionally:
PHP Fatal error: Out of memory (allocated 80740352) (tried to allocate 14592 bytes)
Something telling me it seems my memory_limit is not 128M but being capped at around 80M. Its an apache server. My code is like this NOTE - due to lenght I have cut out the error checks and only shown it for one image check out of the 6. But here it is but I cant see my code causing the problem as most people manage to upload there images:
if(move_uploaded_file($_FILES['uploadedfile_0']['tmp_name'], $move_file_to_directoryname_large))
{
$n_width=100;$n_height=100; /*specify height/width of thumbnail image to be*/
if($_FILES["uploadedfile_0"]["type"]=="image/gif")
{
$im=imagecreatefromgif($move_file_to_directoryname_large);
if(!$im)
{
/*error could occur here if image was say named .gif but was another type like .jpg casing file type error*/
$image_resize_error++;
$array_error_msg_resize[$image_resize_error]="<p class='form_error_messages'>• An unfixable error occurred with your image ('<span class='standard_span'> " .$_FILES['uploadedfile_0']['name']." </span>').</p>";
}
else
{
$width=imagesx($im); $height=imagesy($im);
$newsmallerimage=imagecreatetruecolor($n_width,$n_height);
imagecopyresized($newsmallerimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
$move_file_to_directoryname_small=$target_path_small.$newfilename;
if(function_exists("imagegif"))
{
imagegif($newsmallerimage,$move_file_to_directoryname_small);
$images_db_small[0]=substr_replace($move_file_to_directoryname_small, "", 0, 24);
}
/*frees image from memory */
imagedestroy($newsmallerimage);
}
}
if($_FILES["uploadedfile_0"]["type"]=="image/jpeg")
{
$im=imagecreatefromjpeg($move_file_to_directoryname_large); /*create from image stored in directory specified when moving from /tmp*/
if(!$im)
{
/*error could occur here if image was say named .gif but was another type like .jpg casing file type error*/
$image_resize_error++;
$array_error_msg_resize[$image_resize_error]="<p class='form_error_messages'>• An unfixable error occurred with your image ('<span class='standard_span'> " .$_FILES['uploadedfile_0']['name']." </span>').</p>";
}
else
{
$width=imagesx($im);/*Original picture width is stored*/$height=imagesy($im);/*Original picture height is stored*/
$newsmallerimage=imagecreatetruecolor($n_width,$n_height);
$imagecopyresized($newsmallerimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
$move_file_to_directoryname_small=$target_path_small.$newfilename;
if(function_exists("imagejpeg"))
{
imagejpeg($newsmallerimage,$move_file_to_directoryname_small);
$images_db_small[0]=substr_replace($move_file_to_directoryname_small, "", 0, 24);
}
/*frees image from memory */
imagedestroy($newsmallerimage);
}
}
}
Any ideas? Would this be not a code problem but server problem not having enough RAM installed perhaps?
Thanks for assistance guys and girls