CalmSoul
asked on
Download header cause zip file to be corrupt
We are making a download manager application ...
Download header cause zip file to be corrupt
Please see the code below
Download header cause zip file to be corrupt
Please see the code below
header("Content-type: $mimeType");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".$size);
header("Content-disposition: attachment; filename=\"".$a['name']."\"");
readfile("$pathside");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here's a function for large files:
<?PHP
readfile_chunked($file);
function readfile_chunked($filename ) {
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
// ***** Write output to client
$buffer = fread($handle, $chunksize);
print $buffer;
}
return fclose($handle);
}
?>
<?PHP
readfile_chunked($file);
function readfile_chunked($filename
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
// ***** Write output to client
$buffer = fread($handle, $chunksize);
print $buffer;
}
return fclose($handle);
}
?>
So log as you don't have output buffering turned on (or you can turn it off on the fly), you shouldn't need to do that. PHP is built with mmap support by default which means it doesn't read the file into memory in order to send it - it just streams from disk to network. mmap and sendfile are also supported by apache, and are normally used for delivering all static files.
<?PHP
$file = '/home/test/somefile.dat';
header('Content-Descriptio
header('Content-Type: application/force-download
header('Content-Length: ' . filesize($file));
header('Content-Dispositio
?>