[solved] send dynamic images from single .php page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

[solved] send dynamic images from single .php page

Post 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
Last edited by Burrito on Thu Mar 03, 2005 5:25 pm, edited 2 times in total.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

smpdawg helped me on IM.

echo file_get_contents($myfile);

got me there..

thx smp!
Post Reply