mohammedsk Posted November 16, 2006 Share Posted November 16, 2006 Hi,I upload images to MySQL database using PHP. The images are stored correctly, but some images when fetched back to be displayed in the browser comes out to be incomplete. What I mean by incomplete is that that image comes out to be 1/3 less in height.As a demonstration check out this link. The first image comes from the database, the second image is in a folder.Here are the code two pieces of code I use to display the image.[code]$result=mysql_query("SELECT size from profile_image where username='mohammed'");$row=mysql_fetch_assoc($result);//That is the original resolution $size[0]==width, $size[1]==height$size=explode("x", $row['size']);echo "<img class='userImage' width='$size[0]' height='$size[1]' src=\"fetch_user_image.php?username=mohammed\"><br>"; [/code] [code]$sql = "SELECT image, type FROM profile_image WHERE username='mohammed'"; $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());list($image, $size) = mysql_fetch_array($result); // set the header for the imageheader( "Content-type: $type");echo $image;exit;[/code]Any help is appreciated, Quote Link to comment Share on other sites More sharing options...
btherl Posted November 16, 2006 Share Posted November 16, 2006 How do you know that the images are stored correctly?There is something odd in your code.. you "SELECT image,type" then you list($image,$size) = mysql_fetch_array($result). Those don't match. Quote Link to comment Share on other sites More sharing options...
mohammedsk Posted November 16, 2006 Author Share Posted November 16, 2006 You are right, I am not sure if images are stored correctly. I corrected the error you mentioned, but it did not make a difference.Here is the code I use to insert an image:[code]if(is_uploaded_file($_FILES['userimage']['tmp_name'])) { $imgData =addslashes (file_get_contents($_FILES['userimage']['tmp_name'])); $size = getimagesize($_FILES['userimage']['tmp_name']); $real_name = addslashes ($_FILES['userimage']['name']); $type = $_FILES['userimage']['type']; $sql = "UPDATE profile_image SET image='{$imgData}', type='$type', ". size='$size[0]x$size[1]', name='$real_name' WHERE username='$username'"; mysql_query($sql);}[/code] Quote Link to comment Share on other sites More sharing options...
mohammedsk Posted November 19, 2006 Author Share Posted November 19, 2006 I did it figure it out, it was a matter of the field size in the database. 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.