Forum Moderators: coopster
$img = $_GET["src"];
header("Content-type: image/jpg");
header("Cache-Control: public, max-age=600000");
header("Expires: Tue, 1 Jan 2008 01:00:00 GMT");
header('Content-length: '.filesize($img));
readfile($img);
should be safe for displaying images? The user can't use a browser to download any other type of file except an image. The user can traverse the directories but still can only download an image.
You should restrict it to directories that are safe, and/or check that the filename ends with .jpg.
$img = $_GET["src"];
if(![url=http://us2.php.net/manual/en/function.file-exists.php]file_exists[/url]($img)) {
echo 'File does not exist!';
exit;
}
else if([url=http://us2.php.net/manual/en/function.exif-imagetype.php]exif_imagetype[/url]($img)!= 2) {
echo 'Error! Not correct filetype';
exit;
}
header("Content-type: image/jpg");
header("Cache-Control: public, max-age=600000");
header("Expires: Tue, 1 Jan 2008 01:00:00 GMT");
header('Content-length: '.filesize($img));
readfile($img);
Something like that should do. :)
Good luck!
$img = $_GET["src"];
if(!file_exists($img)) {
header("HTTP/1.0 404 Not Found");
echo 'File does not exist!';
exit;
}
else if(exif_imagetype($img)!= 2) {
header("HTTP/1.1 403 Forbidden");
echo 'Error! Not correct filetype';
exit;
}