Jump to content

Force Dowload


phpretard

Recommended Posts

I am trying to force a download.  It seams to only work with images.  When I try with a pdf the file type is always reads  "application/octet-stream" and is not recognized ... Here is my code.

 

<?php 

$path = $_GET['path'];
$file = "../$path"; // path to file
$ext = $_GET['ext'];  //file extension


if ($ext =="jpg" || $ext =="jpeg"|| $ext =="gif"|| $ext =="png"|| $ext =="psd"|| $ext =="ai"|| $ext =="tif" || $ext =="bmp" || $ext =="zip"|| $ext =="rar"|| $ext =="gzip"|| $ext =="pdf"){
$appType = header('Content-Type: image/$ext');
}else{
$appType = header('Content-Type: application/pdf');
//$appType = header('Content-Type: application/octet-stream');
}

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    echo $appType;
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}

?>

 

Thank you for looking!

Link to comment
https://forums.phpfreaks.com/topic/202816-force-dowload/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.