phpretard Posted May 25, 2010 Share Posted May 25, 2010 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.