Posts Tagged ‘image’

show / download image with PHP

March 9th, 2010

To show a image in browser:

$file_path = ICON_DIR . $_GET['f'];
// TODO check file_path security
$file_name = basename($_GET['f']);
$fileLineArray = file($file_path);
header(‘Content-Type: image/jpeg’);
header(“Content-Disposition:filename=$file_name”);
foreach($fileLineArray as $fileLine)
echo $fileLine;

To force the browser to show the download dialogue, add a attachment header:

header(“Content-Disposition:filename=$file_name”);
header(“Content-disposition: attachment; filename=$file_name”);