Deepak Narwal
Deepak Narwal

Reputation: 401

how to display a image into web page

I want to display an uploaded images into my web page.For doc files i used file_get_contents for displaying the data(not displaying exactly) but in case of images i dont have any idea.Plz tell me

Upvotes: 1

Views: 992

Answers (4)

user2360414
user2360414

Reputation: 27

The simple way is to use

the border, width a

Upvotes: 0

coder
coder

Reputation: 1079

are u storing the image as a file or as a binary data?

if file,

use HTML IMG element.

if binary,

read the bytes and create the image using php gdlibrary

follow this

  1. your image url in the db should be relative to your document root
  2. use in your html or php
  3. you need to make sure the directory structure is appropriate. bcoz there are some limitations on how many files can be stored in a directory. for this, create some directory structure based on first two digits some thing like that. store this even in db table. your db table should have filename, relative path , directory structure.

try it and let me know

Upvotes: 0

Pavunkumar
Pavunkumar

Reputation: 5345

Use <img> tag in your code. It will display the require image in your web page . In image tag , you need specify the image path.

<img src="/home/pavunkumar/my_img.gif" alt="Not able to bring out" >

Here , alt attribute is used to say message , when the image is not able to display in the page because of some other issues, such as size,etc.

Upvotes: 0

Pascal MARTIN
Pascal MARTIN

Reputation: 401172

There are two possible solutions.

For the first one to work, your image has to be accessible via your web-server (i.e. be in a sub-directory of your document root) ; then, you just have to use an <img> tag that points to that image :

<img src="sub-directory/your-image.jpg" alt="my image" />

Of course, up to you to adapt the path to the image ;-)


If you image is not in a public diretory, you cannot use that technique, as your web-server will not be able to serve them.

In this situation, you'll have to use some PHP script to serve the image, and call that PHP script using an <img> tag :

<img src="serve-image?php.id=1234" alt="your image" />

Or like this :

<img src="serve-image.php?img=my-image-name.jpg" alt="your image" />

And this serve-image.php script will just :


Of course, note that you should ensure that this script will not accept to serve any file from your server : it should only serve files in the directory that contains images !

For instance, using something like this should not be permitted (the script should return, for instance, a 404 error) :

<img src="serve-image.php?img=../../../etc/passwd" alt="trying to be bad" />

Upvotes: 2

Related Questions