Tomislav Posted September 23, 2013 Share Posted September 23, 2013 Hi all. I have a web page where user can upload pictures for publishing obituaries. everything worked fine until upgrading server to PHP 5.3.27 Now new pictures are not visible even in my CMS backoffice. Photos uploaded before upgrade are still visible. I can see that pictures are uploaded in folder /images/content/ anyone have some idea? below is code for uploading pictures. Thanks in advance . { if (is_uploaded_file($_FILES['slika']['tmp_name'])) { $path = getenv('DOCUMENT_ROOT').'/images/content/'; $brojac = 1; while (file_exists($path.$brojac.'.jpg')) $brojac = $brojac+1; $slika = $brojac; $filesaved = copy($_FILES['slika']['tmp_name'], $path.'o_'.$slika.'.jpg'); list($width, $height) = getimagesize($path.'o_'.$slika.'.jpg'); $v = exec("convert ".$path.'o_'.$slika.".jpg -resize 150x500 ".$path.$slika.'.jpg'); $v = exec("convert ".$path.$slika.".jpg -crop 150x200+0+0 ".$path.$slika.'.jpg'); } Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/ Share on other sites More sharing options...
jazzman1 Posted September 23, 2013 Share Posted September 23, 2013 (edited) anyone have some idea? Turn on the error_reporting functions on the top of this page, which help you/us what could be causing this problem! Edited September 23, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1450882 Share on other sites More sharing options...
Tomislav Posted September 23, 2013 Author Share Posted September 23, 2013 Turn on the error_reporting functions on the top of this page, which help you/us what could be causing this problem! i have put this in first line <?php // Report all PHP errors error_reporting(-1); and where do I see errors now? Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1450886 Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2013 Share Posted September 23, 2013 Errors should be displayed on the page you're viewing. You may beed to enable display_errors // Report all PHP errors display_errors(true); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1450887 Share on other sites More sharing options...
jazzman1 Posted September 23, 2013 Share Posted September 23, 2013 Put these two lines of code on the top of this file which code you posted above: error_reporting(E_ALL); ini_set("display_errors", 1); Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1450888 Share on other sites More sharing options...
Tomislav Posted September 23, 2013 Author Share Posted September 23, 2013 Put these two lines of code on the top of this file which code you posted above: error_reporting(E_ALL); ini_set("display_errors", 1); I have done that now and no errors are displayed. But i have noticed now that picture is saved in correct folder and named o_503.jpg The letter o stands for original picture, and now it should be copied, resized and named 503.jpg without letter o in front. Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1450893 Share on other sites More sharing options...
jazzman1 Posted September 23, 2013 Share Posted September 23, 2013 $filesaved = copy($_FILES['slika']['tmp_name'], $path.'o_'.$slika.'.jpg'); That's wrong! You cannot use a copy function before the image has been successfully uploaded on the fileserver. Instead a copy function use the move_uploaded_file() ! Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1450895 Share on other sites More sharing options...
Tomislav Posted September 24, 2013 Author Share Posted September 24, 2013 That's wrong! You cannot use a copy function before the image has been successfully uploaded on the fileserver. Instead a copy function use the move_uploaded_file() ! No, image is uploaded on the server, but then it is supposed to be copied for editing ( crop, resize). I have tried with move_uploaded_file() istead copy function, but it is the same. Is there other way to do the same thing? Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1451091 Share on other sites More sharing options...
vinny42 Posted September 24, 2013 Share Posted September 24, 2013 "$v = exec("convert ".$path.'o_'.$slika.".jpg -resize 150x500 ".$path.$slika.'.jpg');" Does the server still allow you to use exec()? Becauset that's a very dangerous thing and is usually disabled. Using the gd functions of PHP is safer and does the same thin to the image. Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1451093 Share on other sites More sharing options...
Tomislav Posted September 24, 2013 Author Share Posted September 24, 2013 (edited) "$v = exec("convert ".$path.'o_'.$slika.".jpg -resize 150x500 ".$path.$slika.'.jpg');" Does the server still allow you to use exec()? Becauset that's a very dangerous thing and is usually disabled. Using the gd functions of PHP is safer and does the same thin to the image. vinny, i think that you have found a problem. this function is not working. everything is done before that, and than when it should be resized and renamed, nothing happens. can you tell me witch gd function will do the job , because i want to have possibility in CMS to crop picture, and than that cropped image is displayed in size 150 width, and height is proportionally to resize %. This is size for all images displayed on page, 150 width. here is link to see http://www.osmrtnica.net/posljednji_pozdravi/str/3/ Thanks a lot. Edited September 24, 2013 by Tomislav Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1451095 Share on other sites More sharing options...
vinny42 Posted September 24, 2013 Share Posted September 24, 2013 Look at imagecopyresampled(), it is a little tricky but if you google for something like "php imagecopyresampled resize example" you should find tons of people who did this. Note; there is also imagecopyresized(), but imagecopyresampled() gives much better results when the image is resized. Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1451098 Share on other sites More sharing options...
Tomislav Posted September 24, 2013 Author Share Posted September 24, 2013 Look at imagecopyresampled(), it is a little tricky but if you google for something like "php imagecopyresampled resize example" you should find tons of people who did this. Note; there is also imagecopyresized(), but imagecopyresampled() gives much better results when the image is resized. tried code below, still not working, going to sleep maybe tomorrow will be better day $path = getenv('DOCUMENT_ROOT').'/images/content/'; $brojac = 1; while (file_exists($path.$brojac.'.jpg')) $brojac = $brojac+1; $slika = $brojac; $filesaved = copy($_FILES['slika']['tmp_name'], $path.'o_'.$slika.'.jpg'); // The file $filename = $path.'o_'.$slika.'.jpg''; // Set a maximum height and width $width = 150; $height = 500; // Content type header('Content-type: image/jpeg'); // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $path.$slika.'.jpg' = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($path.$slika.'.jpg', $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output imagejpeg($image_p, null, 100); Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1451113 Share on other sites More sharing options...
jazzman1 Posted September 25, 2013 Share Posted September 25, 2013 (edited) No, image is uploaded on the server, but then it is supposed to be copied for editing ( crop, resize). Ah....I see that now So, try that: <?php // set the path to img directory $path = $_SERVER['DOCUMENT_ROOT'] . '/images/content/'; if (is_uploaded_file($_FILES['uploaded_file']['tmp_name'])) { $brojac = 1; while (file_exists($path . $brojac . '.jpg')) $brojac = $brojac + 1; $slika = $brojac; $filesaved = copy($_FILES['slika']['tmp_name'], $path . 'o_' . $slika . '.jpg'); // set original image location $img = $path . 'o_' . $slika . '.jpg'; // set our image canvas $canvas_width = 150; $canvas_height = 500; // get width and height of original image list($img_width, $img_height) = getimagesize($img); $ratio_orig = $img_width / $img_height; if ($canvas_width / $canvas_height > $ratio_orig) { $canvas_width = $canvas_height * $ratio_orig; } else { $canvas_height = $canvas_width / $ratio_orig; } // loading in our original image $original = imagecreatefromjpeg($img); // create a blank canvas $canvas = imagecreatetruecolor($canvas_width, $canvas_height); imagecopyresampled($canvas, $original, 0, 0, 0, 0, $canvas_width, $canvas_height, $img_width, $img_height); if (imagejpeg($canvas, $img, 100)) { return true; } else { return false; } Edited September 25, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1451131 Share on other sites More sharing options...
Tomislav Posted October 29, 2013 Author Share Posted October 29, 2013 Ah....I see that now So, try that: <?php // set the path to img directory $path = $_SERVER['DOCUMENT_ROOT'] . '/images/content/'; if (is_uploaded_file($_FILES['uploaded_file']['tmp_name'])) { $brojac = 1; while (file_exists($path . $brojac . '.jpg')) $brojac = $brojac + 1; $slika = $brojac; $filesaved = copy($_FILES['slika']['tmp_name'], $path . 'o_' . $slika . '.jpg'); // set original image location $img = $path . 'o_' . $slika . '.jpg'; // set our image canvas $canvas_width = 150; $canvas_height = 500; // get width and height of original image list($img_width, $img_height) = getimagesize($img); $ratio_orig = $img_width / $img_height; if ($canvas_width / $canvas_height > $ratio_orig) { $canvas_width = $canvas_height * $ratio_orig; } else { $canvas_height = $canvas_width / $ratio_orig; } // loading in our original image $original = imagecreatefromjpeg($img); // create a blank canvas $canvas = imagecreatetruecolor($canvas_width, $canvas_height); imagecopyresampled($canvas, $original, 0, 0, 0, 0, $canvas_width, $canvas_height, $img_width, $img_height); if (imagejpeg($canvas, $img, 100)) { return true; } else { return false; } Hi, still not working. Image is uploaded on correct folder on server with prefix o_ And it is not resized, and not visible in my cms webpage. After removing prefix o_ image is then visible but not resized, and crop function is not working, probably not supported after upgrade PHP server. So what is to solve is resizing image and after that saving image without prefix o_, only number of picture. If anyone have time to take a look for solution I would be very happy. THX Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1456113 Share on other sites More sharing options...
jazzman1 Posted November 3, 2013 Share Posted November 3, 2013 In fact, I've tested the script before to post it. What debugging steps have you taken so far? Did you get some error messages? Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1456715 Share on other sites More sharing options...
Tomislav Posted November 21, 2013 Author Share Posted November 21, 2013 In fact, I've tested the script before to post it. What debugging steps have you taken so far? Did you get some error messages? Hi, jazzman. Had a lot of work, so i have just now tried to solve this thing again. And after some time i have came to this, and that does the job, and saves image in root folder as $slika,jpg. But it is supposed to be saved in root/images/content/ with name as number. I can't find anywhere how to set destination folder. here is code: <?php if (isset($_POST['todoaction']) && $_POST['todoaction'] == 'insert') { if (is_uploaded_file($_FILES['slika']['tmp_name'])) { $path = getenv('DOCUMENT_ROOT').'/images/content/'; $brojac = 1; while (file_exists($path.$brojac.'.jpg')) $brojac = $brojac+1; $slika = $brojac; $filesaved = copy($_FILES['slika']['tmp_name'], $path.'o_'.$slika.'.jpg'); // set original image location $img = $path . 'o_' . $slika . '.jpg'; // set our image canvas $canvas_width = 150; $canvas_height = 500; // get width and height of original image list($img_width, $img_height) = getimagesize($img); $ratio_orig = $img_width / $img_height; if ($canvas_width / $canvas_height > $ratio_orig) { $canvas_width = $canvas_height * $ratio_orig; } else { $canvas_height = $canvas_width / $ratio_orig; } // loading in our original image $original = imagecreatefromjpeg($img); // create a blank canvas $canvas = imagecreatetruecolor($canvas_width, $canvas_height); imagecopyresampled($canvas, $original, 0, 0, 0, 0, $canvas_width, $canvas_height, $img_width, $img_height); if (imagejpeg($canvas, '$slika.jpg', 100)) { return true; } else { return false; } } Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1459421 Share on other sites More sharing options...
Tomislav Posted November 21, 2013 Author Share Posted November 21, 2013 Here is the latest update to post. I got this warning now: Warning: imagejpeg() [function.imagejpeg]: Unable to open '/images/content/503.jpg' for writing: No such file or directory in/home2/smiztita/public_html/cms/required/osmrtnice.php on line 40 And code is: (imagejpeg($canvas, "/images/content/" . $slika.'.jpg', 100)) Seams that we are close to solving problem. Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1459440 Share on other sites More sharing options...
mac_gyver Posted November 21, 2013 Share Posted November 21, 2013 your code has a $path variable that defines the path to where you have/want the source file and the destination file. use that $path variable everywhere you perform a file operation. Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1459443 Share on other sites More sharing options...
Tomislav Posted November 21, 2013 Author Share Posted November 21, 2013 your code has a $path variable that defines the path to where you have/want the source file and the destination file. use that $path variable everywhere you perform a file operation. this code has finally uploaded resized picture to correct folder with correct name. imagejpeg($canvas, "/home2/smiztita/public_html//images/content/" . $slika.'.jpg', 100) But, seems that my agony still remains. Now when i upload picture via my cms, nothing happens in my form, nothing else is uploaded, and nothing is shown. If i chose not to upload picture, everything is ok. Should I give you the whole code, or are you giving up on me Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1459445 Share on other sites More sharing options...
mac_gyver Posted November 21, 2013 Share Posted November 21, 2013 the current code is somewhat a copy/paste of what someone posted in this thread and it contains return statements after the image resizing code. that will cause your code to stop at that point and return to the calling code (or if this is your main code, terminate execution.) at a minimum, you need to remove the logic containing the return statements. Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1459449 Share on other sites More sharing options...
Tomislav Posted November 21, 2013 Author Share Posted November 21, 2013 the current code is somewhat a copy/paste of what someone posted in this thread and it contains return statements after the image resizing code. that will cause your code to stop at that point and return to the calling code (or if this is your main code, terminate execution.) at a minimum, you need to remove the logic containing the return statements. Can you tell me what to remove in code : <?php if (isset($_POST['todoaction']) && $_POST['todoaction'] == 'insert') { if (is_uploaded_file($_FILES['slika']['tmp_name'])) { $path = getenv('DOCUMENT_ROOT').'/images/content/'; $brojac = 1; while (file_exists($path.$brojac.'.jpg')) $brojac = $brojac+1; $slika = $brojac; $filesaved = copy($_FILES['slika']['tmp_name'], $path.'o_'.$slika.'.jpg'); // set original image location $img = $path . 'o_' . $slika . '.jpg'; // set our image canvas $canvas_width = 150; $canvas_height = 500; // get width and height of original image list($img_width, $img_height) = getimagesize($img); $ratio_orig = $img_width / $img_height; if ($canvas_width / $canvas_height > $ratio_orig) { $canvas_width = $canvas_height * $ratio_orig; } else { $canvas_height = $canvas_width / $ratio_orig; } // loading in our original image $original = imagecreatefromjpeg($img); // create a blank canvas $canvas = imagecreatetruecolor($canvas_width, $canvas_height); imagecopyresampled($canvas, $original, 0, 0, 0, 0, $canvas_width, $canvas_height, $img_width, $img_height); if (imagejpeg($canvas, "/home2/smiztita/public_html//images/content/" . $slika . '.jpg', 100)) { return true; } else { return false; } } Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1459452 Share on other sites More sharing options...
jazzman1 Posted November 22, 2013 Share Posted November 22, 2013 But, seems that my agony still remains. Now when i upload picture via my cms, nothing happens in my form, nothing else is uploaded, and nothing is shown. Well, turn on the error_reporting() function on the top of the script and tell us if you get errors with that cms. Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1459501 Share on other sites More sharing options...
Tomislav Posted November 22, 2013 Author Share Posted November 22, 2013 Well, turn on the error_reporting() function on the top of the script and tell us if you get errors with that cms. That is already turned on: <?php ini_set('display_errors', 'On'); // Report all PHP errors error_reporting(-1); if (isset($_POST['todoaction']) && $_POST['todoaction'] == 'insert') After upload is finished, a few seconds after i have only my menu on left side, and on right side where form is supposed to be, everything just vanish. Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1459505 Share on other sites More sharing options...
Solution mac_gyver Posted November 22, 2013 Solution Share Posted November 22, 2013 in your original code, after the two exec(....) statements that resized/cropped the image, you had the remainder of your code that processed the form data? you still need for that code to run. change this - if (imagejpeg($canvas, "/home2/smiztita/public_html//images/content/" . $slika . '.jpg', 100)) { return true; } else { return false; } to this (note that i added a ! to complement the conditional test) - if (!imagejpeg($canvas, "/home2/smiztita/public_html//images/content/" . $slika . '.jpg', 100)) { // do something here when this process fails - some application error reporting/logging perhaps... } Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1459526 Share on other sites More sharing options...
jazzman1 Posted November 22, 2013 Share Posted November 22, 2013 I still don't understand which one of following (bold) statement is true and which one is false. Now when i upload picture via my cms, nothing happens in my form, nothing else is uploaded, and nothing is shown. Quote Link to comment https://forums.phpfreaks.com/topic/282386-problem-with-picture-upload-after-upgrading-php-to-ver5327/#findComment-1459567 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.