Page 1 of 1

[solved] send dynamic images from single .php page

Posted: Thu Mar 03, 2005 5:08 pm
by Burrito
I have some image names saved on my db and I want people to be able to hit a single page on my site with a file id that associates to the image in the database and then have it return the image.

for example:

Code: Select all

<img src="http://www.mysite.com/myfolder/mypage.php?fid=34">
that will return the image associsated with fid of 34.

here's what I've got and it's not working...I've been bugging Feyd about this pretty much all afternoon...but he's feeding his cat now so thought I'd jump here and spread it around some more.
<?
require_once('includes/dbInteract.php');
    
tt_db_connect();
$fid = (isset($_POST['fid']) ? $_POST['fid'] : $_GET['fid']);
$qry = "select * from lp_files where id = ".$fid;
$getfile = mssql_query($qry);
if(
$gtfile = mssql_fetch_assoc($getfile)){
    
$isimg = getimagesize($gtfile['fileloc']);
    
$fsize = filesize($gtfile['fileloc']);
    
header("Content-type: {$isimg['mime']}");
    
header('Content-Disposition: attachment; filename='.$gtfile['fileloc']);
    
header('Content-length: '.$fsize);
}else{
    
$message = "There are no files for that file id";
}
?>
any help is greatly appreciated...

thx,

Burr

Posted: Thu Mar 03, 2005 5:24 pm
by Burrito
smpdawg helped me on IM.

echo file_get_contents($myfile);

got me there..

thx smp!