christo16 Posted May 15, 2007 Share Posted May 15, 2007 So the code lets me upload an image in full resolution and then resizes a thumbnail. It works with small images (less then 800 X 600) but with large images it does not do the thumbnail. It does not fail or give me an error, just doesn't make a thumbnail. Any ideas? if ($_GET[a] == "up"){ $idir = "../../pictures/full/"; // Path To Images Directory $tdir = "../../pictures/thumbs/"; // Path To Thumbnails Directory $twidth = "125"; // Maximum Width For Thumbnail Images $theight = "100"; // Maximum Height For Thumbnail Images if (!isset($_GET['subpage'])) { // Image Upload Form Below ?> <form method="post" action="gallery.php?a=up&subpage=upload" enctype="multipart/form-data"> <ul> <li><p>Picture 1: <input type="file" name="imagefile" class="form"></p></li> </ul> <input name="submit" type="submit" value="Upload!" class="form"> <input type="reset" value="Clear" class="form"> </form> </div> </div> <div id="footer"></div> </div> <? } else if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') { // Uploading/Resizing Script //************************************************************************** //Picture One print 'Picture 1:<br>'; $url = $_FILES['imagefile']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['imagefile']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']); // Move Image From Temporary Location To Permanent Location if ($copy) { // If The Script Was Able To Copy The Image To It's Permanent Location print 'Image uploaded successfully.<br />'; // Was Able To Successfully Upload Image $simg = imagecreatefromjpeg("$idir" . $url); // Make A New Temporary Image To Create The Thumbanil From $currwidth = imagesx($simg); // Current Image Width $currheight = imagesy($simg); // Current Image Height if ($currheight > $currwidth) { // If Height Is Greater Than Width $zoom = $twidth / $currheight; // Length Ratio For Width $newheight = $theight; // Height Is Equal To Max Height $newwidth = $currwidth * $zoom; // Creates The New Width } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) $zoom = $twidth / $currwidth; // Length Ratio For Height $newwidth = $twidth; // Width Is Equal To Max Width $newheight = $currheight * $zoom; // Creates The New Height } $dimg = imagecreate($newwidth, $newheight); // Make New Image For Thumbnail imagetruecolortopalette($simg, false, 256); // Create New Color Pallete $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image $colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use } //End for if($copy) imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It) imagejpeg($dimg, "$tdir" . $url); // Saving The Image imagedestroy($simg); // Destroying The Temporary Image imagedestroy($dimg); // Destroying The Other Temporary Image $full= 'full/'.basename( $_FILES['imagefile']['name']); $thumb= 'thumbs/'.basename( $_FILES['imagefile']['name']); $result = mysql_query('INSERT pictures SET url= "'.$full.'",thumb= "'.$thumb.'"'); //Adds picture info to DB if (!$result) { die ("Could not query the database: <br />". mysql_error()); } print 'Image thumbnail created successfully.<br>'; // Resize successful } else { print '<font color="#FF0000">ERROR: Unable to upload image.</font>'; // Error Message If Upload Failed } } else { print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is '; // Error Message If Filetype Is Wrong print $file_ext; // Show The Invalid File's Extention print '.</font><br>'; } } } //Main End Tag Quote Link to comment https://forums.phpfreaks.com/topic/51537-trying-to-uploadresize-image/ Share on other sites More sharing options...
Wildbug Posted May 15, 2007 Share Posted May 15, 2007 Do the file sizes of the larger images exceed the upload size limit? Quote Link to comment https://forums.phpfreaks.com/topic/51537-trying-to-uploadresize-image/#findComment-253833 Share on other sites More sharing options...
christo16 Posted May 15, 2007 Author Share Posted May 15, 2007 thanks for the reply, There shouldn't be an upload size limit becuase I running this script on a local server. Quote Link to comment https://forums.phpfreaks.com/topic/51537-trying-to-uploadresize-image/#findComment-253879 Share on other sites More sharing options...
phast1 Posted May 15, 2007 Share Posted May 15, 2007 Yeah, I would check your phpinfo() for the limits on post_max_size, upload_max_filesize, and memory_limit.. Also check that max_execution_time and max_input_time are set to longer than you need for uploading the image.. I think that most browsers will also time out after a few minutes regardless of the php.ini settings, so make sure that your upload isn't taking that long.. And yes, PHP always has limits that are specified in the php.ini file regardless of whether you are running it locally or remotely.. Check your phpinfo() for the location of your php.ini file if you do not know where it is.. Quote Link to comment https://forums.phpfreaks.com/topic/51537-trying-to-uploadresize-image/#findComment-253880 Share on other sites More sharing options...
christo16 Posted May 15, 2007 Author Share Posted May 15, 2007 Thanks for the reply, I checked all those things and they seem alright, I just checked my php error log, does this make any sense: "[15-May-2007 14:01:22] PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 10240 bytes) in modules/gallery.php on line 80" Quote Link to comment https://forums.phpfreaks.com/topic/51537-trying-to-uploadresize-image/#findComment-253940 Share on other sites More sharing options...
phast1 Posted May 15, 2007 Share Posted May 15, 2007 Yes, that is definitely the memory_limit default setting of 8MB causing that error.. I would check your phpinfo() output to make sure that the local value of memory_limit is something higher, such as "64M".. Quote Link to comment https://forums.phpfreaks.com/topic/51537-trying-to-uploadresize-image/#findComment-253957 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.