Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem in large size image uploading.

kamill's Avatar
Member
 
Join Date: Dec 2006
Location: within compiler
Posts: 65
#1: Jun 23 '08
Dear All,
I am uploading a image file and after resize the image i am saving it. My script is working fine with small size images but when i am trying to upload big size image, i am getting below error.
Error 500 - Internal server error
An internal server error has occured!
Please try again later.

My ini settings are as below

  • file_uploads: On
  • upload_max_filesize: 20M
  • max_input_time: -1
  • memory_limit: 40M
  • max_execution_time: 50000
  • post_max_size: 8M
System Linux infong 2.4 #1 SMP Wed Sep 26 00:19:50 CEST 2007 i686 GNU/Linux
PHP Version 4.4.8

Same code is working on local server.

Please help me to overcome from this frustrating issue.

Regards,
Kamill

kamill's Avatar
Member
 
Join Date: Dec 2006
Location: within compiler
Posts: 65
#2: Jun 23 '08

re: Problem in large size image uploading.


Hi all,
I have find out that when i commented createthumb() function call, the script become able to upload large image size but i am unable identify the wrong syntax.
My php code is below
[PHP]
$newImage= $_FILES['newImage']['name'];
$name='img'.$_SESSION['id'].'.jpeg';
$newImageName='images/profile/'.$name;
move_uploaded_file($_FILES["newImage"]["tmp_name"],$newImageName);

$newwidth=110;
$newheight=110;
createthumb($newImageNameBig,$newImageName,$newwid th,$newheight );

function createthumb($filename,$target,$newwidth,$newheight )
{
// Get new sizes
list($width, $height) = getimagesize($filename);

// Get Proportional Dimensions
if ($width > $height) {
$thumb_w=$newwidth;
$thumb_h=$height*($newheight/$width);
}
if ($width < $height) {
$thumb_w=$width*($newwidth/$height);
$thumb_h=$newheight;
}
if ($width == $height) {
$thumb_w=$newwidth;
$thumb_h=$newheight;
}

// Center Image
$x = ( $newwidth - $thumb_w ) / 2;
$y = ( $newheight - $thumb_h ) / 2;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Change Background
$white = imagecolorallocate($thumb, 255, 255, 255);
imagefill($thumb, 0, 0, $white);

// Resize
imagecopyresized($thumb, $source, $x, $y, 0, 0, $thumb_w, $thumb_h, $width, $height);
//imagecopyresampled($thumb, $source, $x, $y, 0, 0, $thumb_w, $thumb_h, $width, $height);
// Output
imagejpeg($thumb, $target);
// Free Memory
imagedestroy($thumb);
imagedestroy($source);
}

[/PHP]
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#3: Jun 23 '08

re: Problem in large size image uploading.


I don't think this is a problem with your code, but rather with your server.

You say this is working on your local server, but not you host.
What are the differences between the two?
Are they running the same PHP version with the same settings?

Is it possible that your host is limiting the resources you can use in such a way that it would cut off your script when it is using to much RAM or CPU?
Reply