Welcome to WebmasterWorld Guest from 18.104.22.168
for example, I have images in a folder, these images are also in my database(just the file names). I want to have the page with the image to use something like
//Im actually pulling the $id from database with:
<img src="get_file.php?file=<?php echo $seepic['hash'];?>"/>
where get_file.php has code like:
$hash = $_GET['file'];
//select data from database
$pullinfo = mysql_query("SELECT `filename`,`hash`,`filetype`,`thumb`,`views` FROM `userfiles` WHERE hash = '$hash'") or die("SQL error: ".mysql_error());
$seepic = mysql_fetch_array($pullinfo);
$pic = 'image_folder/'.$seepic['filename'];
// load the file to send:
I have tried many variations of this code, using all sorts of methods found on this forum and others, but the result is always the same! The image does not display on the page.
If anyone can help me it would be great!
Do you need to set the Content-Length header?
$image = imagecreatefromjpeg($path);
imagejpeg($image, NULL, 100);
^this reads the file then sends it to the browser.
^the fpassthru function is another way to send a file to the browser unmodified.
Also, if you use .htaccess at all for rewriting URLs, I'd just quickly recommend hiding the fact that you're using PHP to display the image. For example something like:
RewriteRule ^img/([a-z0-9_]+).jpg$ /get_file.php?file=$1
So your HTML code looks like <img src="/img/file_id123.jpg"> instead of <img src="get_file.php?file=file_id123"/>
When I open just the get_file.php with a get variable like
I get jarbled code if I set no header, and when I set the header the page contains only this :
im stumped as to what else I can try. My main goal for doing this is to hide the real location of the image/video file being displayed, then set a session variable for abit protection. I know this is not solid but its what I need.
[edited by: dreamcatcher at 6:40 pm (utc) on July 5, 2009]
[edit reason] use example.com. Thanks. [/edit]