Jump to content

View Image from database


alena1347

Recommended Posts

I have stored a image in database as it is small dd not upload in folder it got uploade and is shown in database

i stored it with using

$imgData =addslashes (file_get_contents($_FILES['image']['tmp_name']));

then a insert query with $imgData

 

Now when i retrive it with select query from database and display

<td rowspan="12"><?php header('Content-type:image/jpg'); $img=stripslashes($info['image']); echo $img; ?></td>

 

it shows

The image "localhost/final/../f.php?action="view&id=53" cannot be displayed because it contains errors

Link to comment
Share on other sites

Each image you put onto a web page requires its own <img src='url_of_an_image' alt=''> HTML tag.

 

The url_of_an_image for an image that is dynamically output by php must be to a .php script that outputs the correct content type header followed by the image data. Since you would want to use the same .php file for all your dynamically output images, you would want to put an GET parameter on the end of the url that indicates the id of the image. If you search the Internet/forum, you should be able to find example code showing how to do this.

Link to comment
Share on other sites

From php.net:

 

"Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file."

 

The header() is probably causing your first problem.

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.