Jump to content

Image not complete when fetched from MySQL


mohammedsk

Recommended Posts

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 image
header( "Content-type: $type");
echo $image;
exit;
[/code]

Any help is appreciated,
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.