mjurmann Posted September 25, 2007 Share Posted September 25, 2007 Hello, I'm trying to run this script on my site (it worked fine with GoDaddy and Dreamhost shared servers, but not my dedicated server I'm using now): <?php if ($_FILES['uploaded2']['tmp_name'] == NULL) { } else { // This is the temporary file created by PHP $uploadedfile = $_FILES['uploaded2']['tmp_name']; echo $uploadedfile; echo "<br/>"; echo "<br/>"; // Create an Image from it so we can do the resize $src = imagecreatefromjpeg($uploadedfile); echo $src; // Capture the original size of the uploaded image list($width,$height)=getimagesize($uploadedfile); // For our purposes, I have resized the image to be // 600 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched" // or "squashed". If you prefer some max width other than // 600, simply change the $newwidth variable $newwidth=150; $newheight=($height/$width)*150; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $filename = "games_images/thumbs/".$pictureNum."_".$_FILES['uploaded2']['name']; imagejpeg($tmp,$filename,100); echo $filename; imagedestroy($src); imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request // has completed. } ?> For some reason, when I run: $src = imagecreatefromjpeg($uploadedfile); echo $src; Nothing is echoed back from $src. For some reason, imagecreatefromjpeg() is not returning any information to be assigned to the $src variable. However: echo $uploadedfile; Returns the temporary file name from the upload field from the previous page. I recompiled Apache in WHM with GD selected, and GD shows up as enabled in my phpinfo() (viewable at http://www.gameargus.com/test.php), but this function still doesn't seem to be working. As I said, it worked fine on Godaddy and Dreamhost, so there has to be something setup incorrectly here on the dedicated server. Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/ Share on other sites More sharing options...
Orio Posted September 25, 2007 Share Posted September 25, 2007 Try running: <?php $src = imagecreatefromjpeg($uploadedfile); var_dump($src); ?> The information it will give might be helpful. Also turn error reporting to all by writing in the beginning: error_reporting(E_ALL); Maybe you will get a warning that will explain everything. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355209 Share on other sites More sharing options...
mjurmann Posted September 25, 2007 Author Share Posted September 25, 2007 Here is the information I get when I run those commands: var_dump($src) returns: bool(false) error_reporting(E_ALL) returns: Warning: imagecreatefromjpeg(/tmp/phpprDvtk) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/gameargu/public_html/cms/htms/admin-games-image-uploaded.php on line 311 bool(false) Warning: getimagesize(/tmp/phpprDvtk) [function.getimagesize]: failed to open stream: No such file or directory in /home/gameargu/public_html/cms/htms/admin-games-image-uploaded.php on line 315 Warning: Division by zero in /home/gameargu/public_html/cms/htms/admin-games-image-uploaded.php on line 323 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/gameargu/public_html/cms/htms/admin-games-image-uploaded.php on line 324 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/gameargu/public_html/cms/htms/admin-games-image-uploaded.php on line 330 Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/gameargu/public_html/cms/htms/admin-games-image-uploaded.php on line 335 games_images/thumbs/29_commentslogo.jpg Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/gameargu/public_html/cms/htms/admin-games-image-uploaded.php on line 339 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/gameargu/public_html/cms/htms/admin-games-image-uploaded.php on line 340 Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355236 Share on other sites More sharing options...
Orio Posted September 25, 2007 Share Posted September 25, 2007 Well, it's pretty straight forward- It tells you the file doesn't exist. Try saving the file in a temporary folder and then open it from there. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355275 Share on other sites More sharing options...
mjurmann Posted September 25, 2007 Author Share Posted September 25, 2007 How do I go about coding that? I have no idea what I'm doing here...I'm taking a file I've uploaded and running a script to convert it to a thumbnail; however, it is basically telling me that the /tmp folder foesn't exist, even though it does. Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355278 Share on other sites More sharing options...
Orio Posted September 25, 2007 Share Posted September 25, 2007 Create a folder called tmp_imgs in the folder with the script and do it this way: (The part between the *** is my addition) <?php if ($_FILES['uploaded2']['tmp_name'] == NULL) { } else { // This is the temporary file created by PHP $uploadedfile = $_FILES['uploaded2']['tmp_name']; echo $uploadedfile; echo "<br/>"; echo "<br/>"; //******************************************** //Move file to temp folder, using some random filename $tmp_name = "tmp_imgs/".time().rand(0,1000).".jpg"; move_uploaded_file($_FILES['uploaded2']['tmp_name'], $tmp_name); $uploadedfile = $tmp_name; //******************************************* // Create an Image from it so we can do the resize $src = imagecreatefromjpeg($uploadedfile); unlink($tmp_name); //*******I added this too***** Delete the tmp file echo $src; // Capture the original size of the uploaded image list($width,$height)=getimagesize($uploadedfile); // For our purposes, I have resized the image to be // 600 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched" // or "squashed". If you prefer some max width other than // 600, simply change the $newwidth variable $newwidth=150; $newheight=($height/$width)*150; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $filename = "games_images/thumbs/".$pictureNum."_".$_FILES['uploaded2']['name']; imagejpeg($tmp,$filename,100); echo $filename; imagedestroy($src); imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request // has completed. } ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355285 Share on other sites More sharing options...
mjurmann Posted September 25, 2007 Author Share Posted September 25, 2007 Now I'm getting this: tmp_imgs/1190757401460.jpg Warning: imagecreatefromjpeg(tmp_imgs/1190757401460.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/gameargu/public_html/cms/htms/admin-games-image-uploaded.php on line 322 bool(false) Warning: getimagesize(tmp_imgs/1190757401460.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/gameargu/public_html/cms/htms/admin-games-image-uploaded.php on line 326 I used the code you suggested and CHMOD 777 the tmg_imgs directory... <?php if ($_FILES['uploaded2']['tmp_name'] == NULL) { } else { error_reporting(E_ALL); // This is the temporary file created by PHP $uploadedfile = $_FILES['uploaded2']['tmp_name']; echo "<br/>"; echo "<br/>"; //******************************************** //Move file to temp folder, using some random filename $tmp_name = "tmp_imgs/".time().rand(0,1000).".jpg"; move_uploaded_file($_FILES['uploaded2']['tmp_name'], $tmp_name); $uploadedfile = $tmp_name; //******************************************* echo $uploadedfile; Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355293 Share on other sites More sharing options...
Orio Posted September 25, 2007 Share Posted September 25, 2007 Are you sure you named the folder tmp_imgs? Try commenting the line with the unlink() and then upload a file and see if you can find it in the folder. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355305 Share on other sites More sharing options...
mjurmann Posted September 25, 2007 Author Share Posted September 25, 2007 How do you use unlink() ? Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355308 Share on other sites More sharing options...
Orio Posted September 25, 2007 Share Posted September 25, 2007 There's another line I marked with ****** with unlink(), it deletes the temp file. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355310 Share on other sites More sharing options...
mjurmann Posted September 25, 2007 Author Share Posted September 25, 2007 I can confirm that the directory exists and also that it is writable. I used: <?php $target = "tmp_imgs/"; $target = $target .$pictureNum."_banner_". basename( $_FILES['uploaded2']['name']) ; $ok=1; if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } if ($ok==0) { Echo "Sorry your file was not uploaded"; } else { if(move_uploaded_file($_FILES['uploaded2']['tmp_name'], $target)) { chmod($target, 0777); } else { echo "Sorry, there was a problem uploading your file."; } } ?> and the file was correctly placed in this directory. The only problem seems to be using the imagecreatefromjpeg function. I can save the files directly to the sever, but when I need to resize them using imagecreatefromjpeg its giving me these errors Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355311 Share on other sites More sharing options...
Orio Posted September 25, 2007 Share Posted September 25, 2007 Beats me. Seems to be a problem with GD or something. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355314 Share on other sites More sharing options...
mjurmann Posted September 25, 2007 Author Share Posted September 25, 2007 Well thanks anyways for your help Orio Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355317 Share on other sites More sharing options...
Orio Posted September 25, 2007 Share Posted September 25, 2007 No probs, good luck. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355318 Share on other sites More sharing options...
mjurmann Posted September 25, 2007 Author Share Posted September 25, 2007 Orio, if you're out there... In my phpinfo it says: --with-gd' '--with-jpeg-dir=/usr/local' Do I need to specify somewhere that the directory to write the temporary file is /usr/local? Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355333 Share on other sites More sharing options...
mjurmann Posted September 26, 2007 Author Share Posted September 26, 2007 I beg someone to please help me. 15 hours of sitting at the computer and I still can't get this! Quote Link to comment https://forums.phpfreaks.com/topic/70667-problem-with-imagecreatefromjpeg/#findComment-355477 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.