hmaloney
asked on
Displaying an image by reading the file and parsing byte code?
Hi, the way I wrote the question probably is a dead give away that I dont know what I'm talking about!
Background: security on the webserver is set up so that images in a particular folder cannot be browsed and displayed in a webbrowser unless they have a username and password on the folder, and this is the way it needs to stay.
What I need to do is this: display the image file by some other means. The webserver has access to the file by name. I believe you can read the image file and display it somehow. Can someone please help me with the code for this?
Thanks heaps,
Heather.
Background: security on the webserver is set up so that images in a particular folder cannot be browsed and displayed in a webbrowser unless they have a username and password on the folder, and this is the way it needs to stay.
What I need to do is this: display the image file by some other means. The webserver has access to the file by name. I believe you can read the image file and display it somehow. Can someone please help me with the code for this?
Thanks heaps,
Heather.
Yes but however, the imagejpeg() function needs GD to be installed.
Gileze33.
Gileze33.
ASKER
Thanks heaps gileze.
One thing I didn't mention is that I am displaying the image amongst lots of other text, so I don't think the headers line will work for me.
I've tried just printing out the bytes without that, however, and it wont work. Can you please help?
Thanks again.
One thing I didn't mention is that I am displaying the image amongst lots of other text, so I don't think the headers line will work for me.
I've tried just printing out the bytes without that, however, and it wont work. Can you please help?
Thanks again.
Yes thats understandable.
You need to treat the images.php file as though it were an image - so simply use the HTML <img> tag to load in the image to a separate HTML page.
E.g.
<html>
<body>
Hi. Below is an image!
<br>
<img src="images.php?img=whatev er.jpg" alt="wow - an image with a .php extension!">\
</body>
</html>
Sorry about the cheesy example :)
Gileze33.
You need to treat the images.php file as though it were an image - so simply use the HTML <img> tag to load in the image to a separate HTML page.
E.g.
<html>
<body>
Hi. Below is an image!
<br>
<img src="images.php?img=whatev
</body>
</html>
Sorry about the cheesy example :)
Gileze33.
ASKER
Sorry, how does that work with the other code you gave me?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ah! You're a star. I finally understood what you meant, and it worked like a gem. Thank you!
No problem, glad to be of help.
Gileze33.
Gileze33.
Then create a file such as images.php, then when you want say image.jpg, call images.php?img=image.jpg.
SOURCE OF images.php:
<?php
$img = $_GET['img'];
$path = "\path to images folder leaving in trailing slash\";
$instr = fopen($path.$img,"rb");
$bytes = fread($instr,filesize($pat
header("Content-type: image/jpeg");
echo $bytes;
?>
Hope this helps :)
Gileze33.