Image Switch
Moderator: General Moderators
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
Image Switch
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?
A simple version...
image.php?id=1234
image.php?id=1234
Code: Select all
<?php
//query database for file location and mime type
header("Content-type: " . $mime_type);
readfile($file_location);
?>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();
}
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
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.
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.