ajoo Posted May 17, 2017 Share Posted May 17, 2017 (edited) Hi all ! I just recreated an ubuntu web server since I lost the earlier one and I am consistently getting these messages when I try and display / save images [Wed May 17 14:30:15.717043 2017] [:error] [pid 1362] [client 103.232.151.16:62901] PHP Warning: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: \b\n in /var/www/path/to/fr_function.php on line 151, [Wed May 17 14:30:15.717179 2017] [:error] [pid 1362] [client 103.232.151.16:62901] PHP Fatal error: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: Unsupported marker type 0x7e in /var/www/path/to/fr_function.php on line 151, and line 151 happens to be if($mime==="image/jpeg" || $mime==="image/jpg" ) $src = imagecreatefromjpeg($tmp_filename); and mysqli gives the 1406 error code (data too long for the column ). The datatype I am using is the blob and the image size is less than 500K always. I have checked $tmp_filename and that path is correct. Even $src returns true and yet this is crashing. I have checked my image files and they are not corrupt or so I think since they display correctly in any image editor or windows image viewer. There is plenty of space on my disk so this is not a disk space issue. If anyone can shed some light on this. Thanks loads ! PS. This code was working perfectly well earlier ( till about 2 days ago). There have been no changes in the code at all. Only a new server and configuration. Edited May 17, 2017 by ajoo Quote Link to comment Share on other sites More sharing options...
dalecosp Posted May 17, 2017 Share Posted May 17, 2017 There's a note in a very old bug ticket at PHP net ... "I reset the field to MEDIUMBLOB and this went away", basically:https://bugs.php.net/bug.php?id=10420 Might be worth a shot? Quote Link to comment Share on other sites More sharing options...
ajoo Posted May 18, 2017 Author Share Posted May 18, 2017 (edited) Hi dalecosp, Thank you for the response. I have tried as suggested in the ticket but it did not work for me. The error persists. Edited May 18, 2017 by ajoo Quote Link to comment Share on other sites More sharing options...
ajoo Posted May 19, 2017 Author Share Posted May 19, 2017 (edited) Hi all, I am at a dead end with these errors that I am getting consistently : [Fri May 19 09:55:02.376485 2017] [:error] [pid 9592] [client 103.232.151.16:56171] PHP Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: invalid code lengths set\n in /var/www/path/to/fr_function.php on line 152, [Fri May 19 09:59:51.842798 2017] [:error] [pid 9589] [client 103.232.151.16:56196] PHP Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: invalid stored block lengths\n in /var/www/path/to/fr_function.php on line 152, [Fri May 19 10:07:03.234707 2017] [:error] [pid 9630] [client 103.232.151.16:56234] PHP Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: invalid distance code\n in /var/www/path/to/fr_function.php on line 152, and this is the block of code where this occurs : $tmp_filename=$_FILES['image']['tmp_name']; // temporary file . . if($mime==="image/jpeg" || $mime==="image/jpg" ) $src = imagecreatefromjpeg($tmp_filename); elseif($mime==="image/png") $src = imagecreatefrompng($tmp_filename); else $src = imagecreatefromgif($tmp_filename); if I modify this to check the value of $src like below :- if($mime==="image/jpeg" || $mime==="image/jpg" ) { $src = imagecreatefromjpeg($tmp_filename); if($src) echo "True returned:"; else echo "False Returned"; } elseif($mime==="image/png") $src = imagecreatefrompng($tmp_filename); else $src = imagecreatefromgif($tmp_filename); exit(); then I get !! True Returned !!!!???? Now how is that possible ? if the function returns a true value why does it fail otherwise in the normal flow and the errors all occur at line 151 or 152 which is the if-else block above depending upon whether I upload a jpeg or png image ? Kindly someone please help with this issue. I am completely baffled ! Thanks all ! P.S. The same code works absolutely fine on a xampp with no issues at all but that's on an earlier php version (5) while this is the 7.0 version running on aws server on ubuntu1604, php version. Edited May 19, 2017 by ajoo Quote Link to comment Share on other sites More sharing options...
ajoo Posted May 19, 2017 Author Share Posted May 19, 2017 Hi all ! I have been trying to find some way out of this issue and i tried the code from the manual for the functions imagecreatefromjpeg() and imagecreatefrompng() and to my great surprise it worked with my files. So that makes me even more clueless if anything. Guru kindly may come to the rescue ! Thanks loads ! Quote Link to comment Share on other sites More sharing options...
requinix Posted May 21, 2017 Share Posted May 21, 2017 It looks like you're testing this code with a couple of JPEG and PNG images. Can you attach them here, or otherwise upload them somewhere accessible? Quote Link to comment Share on other sites More sharing options...
ajoo Posted May 21, 2017 Author Share Posted May 21, 2017 Hi requinix, thanks for moving my question. Yes sure i can provide the files. Will do so in a little while. Thanks. Quote Link to comment Share on other sites More sharing options...
DulongC Posted May 21, 2017 Share Posted May 21, 2017 What do you get if you run this: <?php var_dump(gd_info()); ?> Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 21, 2017 Share Posted May 21, 2017 By the way, this is exactly why storing images in a database is really not such a great idea. File storage is much more robust, because as long as your filesystem doesn't get corrupted, nothing will happen to the data. In a database, many things can happen: wrong types, wrong settings, wrong queries, bugs etc. So I strongly recommend you export the images to the filesystem (after a full database backup, of course). 2 Quote Link to comment Share on other sites More sharing options...
ajoo Posted May 21, 2017 Author Share Posted May 21, 2017 Hi all !! Thanks for the replies ! @ Requinix : Please find the links below to the images ! http://imgur.com/OSKre45 http://imgur.com/6ellxzk http://imgur.com/JUUHMCj http://imgur.com/PMOg065 http://imgur.com/luvetMs http://imgur.com/qTt65GW http://imgur.com/0k3hBrh http://imgur.com/KprdyeJ http://imgur.com/LohPDSC http://imgur.com/X7HtD92 http://imgur.com/66GvnTm http://imgur.com/vO3UcDu http://imgur.com/laDjYGx http://imgur.com/cYjv691 http://imgur.com/MPAFZpY @DulongC : Hi, Here is the output of the gd_info: array(12) { ["GD Version"]=> string(5) "2.1.1" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPEG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XPM Support"]=> bool(true) ["XBM Support"]=> bool(true) ["WebP Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) } @ Guru Jacques ! Definitely I will do it sir. However, the error occurs while I am just readying the file for resizing to fit in the preview window and before I submit it for saving it on the disk in the uploads folder. Once this works I will simply save the filename in the DB instead of saving the image_data (blob). createimagefromjpeg($file) triggers the area and is baffling since in an example from the PHP manual it gives the correct output. Thanks loads all for the inputs ! Hoping to resolve this soon with your help. 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.