A client has just asked me to fix an issue with their webside. I did not build it but here is what’s happening.
The images are stored in the db as longblobs. Before moving to a new server, everything was working a ok. On the new server, some images only display partially. Even though the image is displayed at desired width and height, over a half of the image is either white or gray. EDIT: Only images uploaded after the server change are affected!
This is used for reading the image into a string for db insertion:
move_uploaded_file($_FILES['imagefile1']['tmp_name'],'tmppic.img')) $tmpstr = fopen('tmppic.img','rb'); $image = addslashes(fread($tmpstr,filesize('tmppic.img')));
Here are the PHP functions used for displaying the images: imagecreatefromstring, imagecreatetruecolor, imagecopyresampled, imagejpeg
Since this has started happening after the server move, I am suspecting server configuration.
What is going on?
Ok, figured it out. Looking at the code below.
The uploaded file is moved into the tmppic.img file. That file is constantly used. The problem is that filesize(‘tmppic.img’) is returning the size of the file before
move_uploaded_file. So, if the previous tmppic.img had a 120k filesize and the new uploaded file is larger, only 120K worth of info is read, thus the gray area in the pictures.I fixed the issue by replacing filesize(‘tmppic.img’) with
Is this a bug?