Page 1 of 1

Image Switch

Posted: Thu Jun 08, 2006 10:09 pm
by tecktalkcm0391
Is their a way to make a image switch... Like the image url would look like: images.php?4545 and then the php code would go and get the image that matches up with the code 4545 and send it as a image file back to the page that is requesting the image?

Posted: Thu Jun 08, 2006 10:15 pm
by PrObLeM
A simple version...

image.php?id=1234

Code: Select all

<?php
//query database for file location and mime type
header("Content-type: " . $mime_type);
readfile($file_location);
?>

Posted: Thu Jun 08, 2006 10:18 pm
by neophyte
You want to force a download of an image? Then you'll want to user header(); Something like this should work:

Code: Select all

 
if(is_file($CFG->absolute_path.$filepath)){
    header("Cache-control: private");
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=".$file);
    header("Content-length: ".filesize($filepath)."\n");
    //send file contents
    $fp=fopen($filepath, "r");
    fpassthru($fp);
} else {
	header('location: http://'.$CFG->domain);
	die();
}

Posted: Fri Jun 09, 2006 9:47 am
by pickle
Do a search for 'secure download' or 'PHP as image' or something similar. This has been discussed many times before.

Posted: Fri Jun 09, 2006 10:03 am
by bokehman
Why not just stick to a proper image URL? What's your point?

Posted: Fri Jun 09, 2006 8:55 pm
by tecktalkcm0391
I wanted the php code to get a file based on inputed data VIA Get from the URL.

Like for an avator type thing:
page.php?gender=male&picture=3

The page.php file would then be like ok i have to get male 3 and then get the picture: image_male_3.gif

If that would work, then my website creation would be a lot easier.