Force Download Files Broken Headers wrong?
Posted
by
Sinan
on Stack Overflow
See other posts from Stack Overflow
or by Sinan
Published on 2011-12-08T15:46:33Z
Indexed on
2012/07/05
21:16 UTC
Read the original article
Hit count: 315
if($_POST['mode']=="save") {
$root = $_SERVER['DOCUMENT_ROOT'];
$path = "/mcboeking/";
$path = $root.$path;
$file_path = $_POST['path'];
$file = $path.$file_path;
if(!file_exists($file)) {
die('file not found');
} else {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-Type: application/force-download');
header("Content-Disposition: attachment; filename=\"".basename($file)."\";" );
header("Content-Length: ".filesize($file));
readfile($file);}}
As soon as i download the file and open it i get an error message. When i try to open a .doc i get the message : file structure is invalid. And when i try to open a jpg : This file can not be opened. It may be corrupt or a file format that Preview does not recognize.
But when i download PDF files, they open without any problem.
Can someone help me?
P.s. i tried different headers including : header('Content-Type: application/octet-stream');
© Stack Overflow or respective owner