Hello Everyone...
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
Hello Everyone...
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
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
try it and let me know
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 :
Content-type
header -- see the header
function.readfile
function.
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" />
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.