I cannot download files other than those in plain text
Posted: Thu Jun 05, 2008 10:05 am
Everah | Please use bbCode tags when posting code in the forums.
Hi,
I combined the info in several online tutorials and finally managed to make my upload/download feature work, but when I try to download files, I can only download or open files in plain text correctly. All the files in any other format are broken. The size looks fine, but the format is messed up. I try to type in specific file types instead of using $type variable, but it does not change anything. Below are the code I am using. They may appear silly
, but please give some suggestions. Thank you very much.
---------------------------------------------------------------
---------------------------------------------------------
Thank you again.
Everah | Please use bbCode tags when posting code in the forums.
Hi,
I combined the info in several online tutorials and finally managed to make my upload/download feature work, but when I try to download files, I can only download or open files in plain text correctly. All the files in any other format are broken. The size looks fine, but the format is messed up. I try to type in specific file types instead of using $type variable, but it does not change anything. Below are the code I am using. They may appear silly
---------------------------------------------------------------
Code: Select all
//connect to db and run an query to get the file info above this point.
list($filename, $type, $size, $filePath) = $result->fetchRow();
header("Content-Disposition: attachment; filename=$filename");
header("Content-Length: $size");
header("Content-Type: $type");
header("Accept-Ranges: bytes");
header("Pragma: no-cache");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-transfer-encoding: binary");
readfile($filePath);
exit;Thank you again.
Everah | Please use bbCode tags when posting code in the forums.