Jump to content

[SOLVED] help displaying images


mattcairns

Recommended Posts

I am storing uploaded images in a non-web accessible folder(for security reasons), and need to display them in an HTML table. I've been working on this all week, and haven't been able to find a solution that did not involve using headers. I can't use headers, as far as I know, due to these images being in the body of the document. Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/30795-solved-help-displaying-images/
Share on other sites

You can store the images directly into your MySQL database, although it may be difficult to backup because of the huge binary data that will be in there. However, it is the most secure way, other than using headers, to display your images and not have them accessible through the web.

Here is a good tutorial:

http://www.phpfreaks.com/tutorials/85/0.php

Hop ethat helps!
thanks for the suggestion, but while waiting i found the solution i was looking for. here it is for anyone who may need it.

code to display image on page:
[code]
<img src='disp_images.php?dir=IMAGE_DIRECTORY&img=IMAGE_NAME'>
[/code]

code to display image (disp_images.php):
[code]
<?
##GET URL VARIABLES
$dir = $_GET['dir'];
$img = $_GET['img'];

##CREATE FILE PATH
$file_path = "/PATH/$dir/$img";

chmod("$file_path", octdec(0777));
$handle = fopen($file_path, "rb");
$contents = fread($handle, filesize($file_path));
fclose($handle);
chmod("$file_path", octdec(0755));

$img_type = mime_content_type($img);
header('Content-type: $img_type');
print "$contents";

?>
[/code]

Hope this helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.