Scotty2024 Posted November 6, 2009 Share Posted November 6, 2009 I am having problems with imagecreatefromjpeg() hanging up while uploading files ~400 KB or larger. Am I doing anything wrong? Here is an example for jpg files: upload form <form action="upload.php" method="post" enctype="multipart/form-data"> Picture: <input name="userfile" type="file" id="userfile"> <br /> <input type="submit" name="uploadPic" value="Upload" /> </form> upload.php if(isset($_POST['uploadPic'])) { $image = $_FILES['userfile']; //assuming user did upload an image. error checking not shown. switch($image['type']) { case "image/pjpeg": case "image/jpg": case "image/jpeg": jpg_processing($image); break; //case gif and png... } function jpg_processing($picture) { $fileName = $picture['name']; $tmpName = $picture['tmp_name']; $fileSize = $picture['size']; $fileType = $picture['type']; $size = getimagesize($tmpName); //Resize image to correct size if($size[0] > $size[1]) //width > height { if($size[0] > 604) { $h_max = ($size[1] * 604)/$size[0]; $w_max = 604; } else { $h_max = $size[1]; $w_max = $size[0]; } } else if($size[0] < $size[1]) { if($size[1] > 604) { $w_max = ($size[0] * 604)/$size[1]; $h_max = 604; } else { $h_max = $size[1]; $w_max = $size[0]; } } else if($size[0] == $size[1]) { if($size[0] > 604 && $size[1] > 604) { $h_max = 604; $w_max = 604; } else { $h_max = $size[1]; $w_max = $size[0]; } } $w = $size[0]; $h = $size[1]; $x_ratio = $w_max/$w; $y_ratio = $h_max/$h; if ($w <= $w_max && $h <= $h_max) { $w_tn=$w; $h_tn=$h; } else if (($x_ratio * $h) < $h_max) { $h_tn=ceil($x_ratio*$h); $w_tn=$w_max; } else { $w_tn = ceil($y_ratio * $w); $h_tn= $h_max; } //done with resizing $src = imagecreatefromjpeg($tmpName); //THIS LINE hangs! Doesn't make it past here. $dst = imagecreatetruecolor ($w_tn, $h_tn); imagecopyresized($dst, $src, 0, 0, 0, 0, $w_tn, $h_tn, $w,$h); imageinterlace($dst, 1); $out_file= '/pictures/'. mt_rand() . '.jpg'; $location = 'http://website.com' . $out_file; imagejpeg ($dst, $out_file, 100); } I don't know why it hangs up on imagecreatefromjpeg(). The browser is blank and simply shows "Done" in the status bar. I have read that this happens if the image doesn't have an EOF tag. I have tried several different images and it still hangs. However, if I upload small images like ~100 KB or less, it works. Do I have an error in my code I am over loooking? Thanks! Link to comment https://forums.phpfreaks.com/topic/180594-imagecreatefromjpeg-hangs/ Share on other sites More sharing options...
Scotty2024 Posted November 7, 2009 Author Share Posted November 7, 2009 Here is an update. I am pretty sure that the script works for all images. I tried it on a different server with the same images and everything worked as it should. I now believe that it is the fault of the server. This script is failing on 1and1.com servers (I am not a fan of this company). I know that the GD Graphics Library is required for this script. To make sure the library is installed I tried phpinfo(); (in info.php) but that also fails on this server. For some reason it pulls my css style sheet, header graphic and required navigation php file. I have no clue why or how it gets all that when all I have is <?PHP phpinfo(); ?> in the info.php file. Can anyone tell me if 1and1.com has the GD graphics library installed and what version? Also, why does this script fail for large images (~400 KB or larger) on 1and1.com servers and not other servers? 1and1 is definitely frustrating! Better yet, can anyone tell me how to upload and resizes images a different way that 1and1 will like? Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/180594-imagecreatefromjpeg-hangs/#findComment-952929 Share on other sites More sharing options...
Scotty2024 Posted November 7, 2009 Author Share Posted November 7, 2009 I tried a simple upload script without the resizing just to see if I could upload images larger than 400 KB. The script below works, however I don't know how to resize the image which is required for my application. Can anyone help me adapt this script below to resize the image? <?php if ($_REQUEST[completed] == 1) { $newname = uniqid("whc").".jpg"; move_uploaded_file($_FILES['mailfile']['tmp_name'], "pictures/$newname"); } ?> <html> <head><title>Upload page</title></head> <body><h1>Image Uploader</h1> <?php if ($_REQUEST[completed] != 1) { ?> <b>Please upload an image</b><br> <form enctype=multipart/form-data method=post> <input type=hidden name=MAX_FILE_SIZE value=1500000> <input type=hidden name=completed value=1> Picture: <input type=file name=mailfile><input type=submit></form> <?php } else { ?> <b>Uploaded!</b> <?php } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/180594-imagecreatefromjpeg-hangs/#findComment-952941 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.