PHP - Corrupted Downloads
Posted: Thu Jan 19, 2006 8:37 am
hawleyjr | Please use
hawleyjr | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]Code: Select all
//This is a script being called from another file to download files
//from a non-web accessible directory. The files download fine
//It's the right size, and everything looks right, but the files
//are corrupted. Except for .txt files
//PHP Version 4.3.8 Apache 2.0.50
if ($download) {
$dquery = mysql_query("SELECT file from files where id='$fid'") or die (mysql_error());
while ($row = mysql_fetch_array($dquery)) {
$filename = $row[file];
$dir = '/home/container/files/' . $filename;
$file = fopen($dir, 'rw');
//set some HTTP headers
Header('Content-Type: application/x-octet-stream');
Header('Content-Transfer-Encoding: binary');
Header('Content-Length: ' . filesize($dir));
Header('Cache-Control: no-cache, must-revalidate'); //HTTP 1.1
Header('Cache-Control: post-check=0, pre-check=0', false); //HTTP 1.1
Header('Pragma: no-cache'); //HTTP 1.0
Header('Content-Description: Whatever the file is');
Header('Content-Disposition: attachment; filename="'.$filename.'"');
Header('Title: ' .$filename);
while(!feof($file)) {
print(fread($file, 4096));
fclose($file);
}
}
}Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]