Woodburn2006 Posted April 12, 2009 Share Posted April 12, 2009 i am creating a script to upload images to the server. the script works fine with smaller images but when i try to upload a large sized image it does not work. function createthumb($name,$filename,$new_w,$new_h) { $system=explode('.',$name); // split filename either side of the '.' if (preg_match('/jpg|jpeg/',$system[1])){ // if extension is jpg or jpeg $src_img=imagecreatefromjpeg($name); // create a copy of the image in jpg } if (preg_match('/png/',$system[1])){ // if extension is png $src_img=imagecreatefrompng($name); // create a copy of the image in png } $old_x=imageSX($src_img); // gets width of original image $old_y=imageSY($src_img); // gets height of original image if ($old_x > $old_y) { // if img is wider than high $thumb_w=$new_w; // sets width variable of new img $thumb_h=$old_y*($new_h/$old_x); // sets height variable by doing: height = original width * (100 / original height) } if ($old_x < $old_y) { // other way around from setting wider than high $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { // if img is square sets variabls straight forwardly $thumb_w=$new_w; $thumb_h=$new_h; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); // creates image imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // copies into new image if (preg_match("/png/",$system[1])) // if old file extension is png { imagepng($dst_img,$filename); // extension of new image is png } else { imagejpeg($dst_img,$filename); // else extension of new image is jpeg or jpg } imagedestroy($dst_img); //destroys variable imagedestroy($src_img); } any ideas why this may be happening. to see the results got to http://www.ontherocks.me.uk/cp user: lee pass: ontherocks Quote Link to comment Share on other sites More sharing options...
schilly Posted April 12, 2009 Share Posted April 12, 2009 check your php config file to see what your max upload size is then use ini_set in your script to change it. ex. ini_set('post_max_size', '20M'); Quote Link to comment Share on other sites More sharing options...
Woodburn2006 Posted April 13, 2009 Author Share Posted April 13, 2009 how do i look up my php config file? Quote Link to comment Share on other sites More sharing options...
Philip Posted April 13, 2009 Share Posted April 13, 2009 <?php phpinfo(); ?> Quote Link to comment Share on other sites More sharing options...
Woodburn2006 Posted April 14, 2009 Author Share Posted April 14, 2009 my max upload is 12mb so that isnt a problem, would it be the max_execution_time as that is set to 30 seconds? if so how would i change it go last longer or even infinately? Quote Link to comment Share on other sites More sharing options...
kodosai Posted April 14, 2009 Share Posted April 14, 2009 my max upload is 12mb so that isnt a problem, would it be the max_execution_time as that is set to 30 seconds? if so how would i change it go last longer or even infinately? I usually only call this at run-time which would be done by putting this at the top of the script file <?php set_time_limit(0); ?> Quote Link to comment Share on other sites More sharing options...
Woodburn2006 Posted April 14, 2009 Author Share Posted April 14, 2009 it still seems to crash part way through, if i down size the images manually then it works but if i try to put a photo that is staright from the camera unedited then it crashes for some strange reason Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 14, 2009 Share Posted April 14, 2009 You are either getting an upload error due to the size or a memory error due to the resizing. Find out if it is a memory problem by adding the following two lines immediately after your first opening <?php tag - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
Woodburn2006 Posted April 14, 2009 Author Share Posted April 14, 2009 i have this code at the beginning of the script: ini_set ("display_errors", "1"); error_reporting(E_ALL); set_time_limit(0); and these are the errors i get Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit in safe mode in /customers/ontherocks.me.uk/ontherocks.me.uk/httpd.www/cp/images/add.php on line 5 Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 15552 bytes) in /customers/ontherocks.me.uk/ontherocks.me.uk/httpd.www/cp/functions.php on line 19 looking like a combination. anything i can do about this? Quote Link to comment Share on other sites More sharing options...
schilly Posted April 15, 2009 Share Posted April 15, 2009 add this in: ini_set('memory_limit','20M'); remove the set_time_limit then see if it works. Quote Link to comment Share on other sites More sharing options...
Woodburn2006 Posted April 15, 2009 Author Share Posted April 15, 2009 now i ge tthis: Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 15552 bytes) in /customers/ontherocks.me.uk/ontherocks.me.uk/httpd.www/cp/functions.php on line 19 starting to get a bit irritating now. no matter what memory limit im entering it comes up with the same error msg and same bytes Quote Link to comment Share on other sites More sharing options...
schilly Posted April 15, 2009 Share Posted April 15, 2009 hmmm maybe contact the host. any memory errors i get usually fix as soon as i bump up the memory. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 15, 2009 Share Posted April 15, 2009 20M is only 20971520 bytes, so had that worked it would have reduced the amount of memory. Assuming you put that ini_set() statement in your code before the point that the code needed more memory, your host has disabled your ability to change the memory_limit. The safe_mode does not state it prevents you from changing this, but that might just be a documentation error. You need to ask your host if or how you can change the memory_limit. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.