Thursday, June 27, 2013

Output or echo an Image or File using PHP script

$file = 'image.jpg'; 
 
$obj = header($file);
if(isset($obj["mime"])) {
    header('Content-Type:'.$obj["mime"]);
} else {
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
}

header('Expires: 0');
header('Pragma: public');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Content-Disposition: inline; filename="some name.jpg" ');  
header('Content-Length: ' . filesize($file));

readfile($file);
exit;

1 comment:

  1. It is nice post and I found some interesting information on this blog, keep it up. Thanks for sharing. . .
    Yii Framework Development Company in India

    ReplyDelete