mattachoo Posted February 20, 2009 Share Posted February 20, 2009 Hello there! I have a problem here that is bugging the hell out of me and was wondering if anyone could give me some insight. I will try to explain my problem in the greatest amount of detail that I can. I have written a script for a client that allows him to "add new products" to his webpage. In this form, the user can select a hi-res picture of the product for upload. Upon upload, my script takes this image and makes two copies of the image; one of width 50px, and one of width 183px, for thumbnail purposes. The client contacted me for this project before owning webspace himself. So, while I was writing the code, I tested it on my own site. I finished writing all the code, and everything worked fine on my end. Now he has bought the webspace, and I have started transferring all the files over to his site so we can get this thing up and running. This is where the problem comes in. After I transferred the scripts and such over to his site, the image resizing script stopped working. I was able to traack down where my script was failing, and it happens when I try and invoke a imagecreatefromjpeg() function. I have tried contacting the tech support people for the website, but they have been useless to me. Here is the snippet of my code: <?php $shit = "http://www.theguyswebsite.com/images/products/"; // The file $filename = $_POST['fname']; $path_parts = pathinfo($filename); $imageWithExt = $path_parts['basename']; $extension = $path_parts['extension']; $imageWithoutExt = basename($imageWithExt, ".".$extension); //echo "with ".$imageWithExt." without ".$imageWithoutExt."<br>"; list($width2, $height2, $type2, $attr2) = getimagesize($filename); //echo "<h4>width ".$width2." height ".$height2." type ".$type2." attr ".$attr2."</h4>"; //do the second thumbnail $width_2 = 183; $num183 = 183/$width2; $height_2 = $height2*$num183; //working // Resample $image_p2 = imagecreatetruecolor($width_2, $height_2); //////////////////////////////////////////////////////// //CODE FAILS HERE!!! DAMNIT! $image4 = imagecreatefromjpeg($filename); //////////////////////////////////////////// imagecopyresampled($image_p2, $image4, 0, 0, 0, 0, $width_2, $height_2, $width2, $height2); // Output ob_start(); imagejpeg($image_p2, null, 100); $thefile2 = ob_get_contents(); ob_end_clean(); //the thumbnail name will be the //same, only it will have a "_thumb2" added to //the end of its filename $newname2 = $imageWithoutExt.'_thumb2'; $destination2 = 'images/products/'.$newname2.'.jpg'; if (!$handle2 = fopen($destination2, 'w')) { echo 'Cannot Open (' . $destination2 . ')'; } else { if (fwrite($handle2, $thefile2) === FALSE) { echo 'Cannot write to file (' . $destination2 . ')'; } else { echo 'Thumbnail 2 was sucessfully saved!'; } fclose($handle2); fclose($handle); } ?> I know my code is sloppy, and my variable names are a bit weird, but this code works I tell ya! Oh, and I switched out the real website name with theguyswebsite.com, so don't mind that. I know for a fact that this code works. The problem does not lie there. If this snippet won't work, that is because it is a snippet, and not the complete file. The problem doesn't lie with my code, is has to do with the web host. So, my question for you guys is, what could possible make the function imagecreatefromjpeg() fail? I have a hunch there is some funny business going on in my php.ini file that is causing this problem, but I haven't the slightest idea what it actually is. I also know this isn't a function that the web host blocks because my website, (the one where this code executes just fine and does what it is supposed to do), yeah, my website is hosted through the same company. If anyone has any information on this or could give me any insight to where to look to see where the problem in (by looking at the information by doing a phpinfo() maybe?) I would greatly appreciate it. I just can't figure this one out. Sorry for the long post, but I didn't want to leave anything out. Again, thank you very much in advance if you help me out! I almost forgot, I also got this error message one time: Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 5760 bytes) in /usr/local/psa/home/*******/addproduct.php on line 218" Thanks again! -Matt Quote Link to comment Share on other sites More sharing options...
angelcool Posted February 20, 2009 Share Posted February 20, 2009 Try ini_set("memory_limit","15M"); at the beginning of your script. Also check this out: http://www.google.com/search?q=Fatal+error%3A+Allowed+memory+size+of+8388608+bytes+exhausted+&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a Good Luck. Angel Quote Link to comment Share on other sites More sharing options...
mattachoo Posted February 20, 2009 Author Share Posted February 20, 2009 The problem was with the memory_limit value in the php.ini file. Once I increased it from 8M to 16M, the script worked fine. Quote Link to comment Share on other sites More sharing options...
angelcool Posted February 20, 2009 Share Posted February 20, 2009 That's exactly what init_set (http://us.php.net/ini_set) does, the advantage is that by using this function it will modify the specified parameter (in this case memory_limit) only for the script it was declared on, thus all other scripts will still have the original restriction, kinda give you a bit more secure environment. Good thing you figured it out though!. Angel 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.