This is weird.
I have a script which sends local zip files to the user via browser. The script has worked fine so far without any problems. Today my colleague notified me about the script is sending zero-length files.
Some background info:
UPDATES:
is_readable()
returns 1$zip_file
holds the file path$zip_name
holds the zip nameerror_reporting
is On
(E_ALL
) shows nothingSnippet in question:
if (file_exists($zip_file)) {
header('Content-type: application/zip');
header('Content-disposition: filename="' . $zip_name . '"');
header("Content-length: " . filesize($zip_file));
readfile($zip_file);
exit();
}
How can i debug this easily?
Thanks in advance, fabrik
http://www.php.net/manual/en/function.readfile.php#102137 :
It should be noted that in the example:
header('Content-Length: ' . filesize($file));
$file should really be the full path to the file. Otherwise content length will not always be set, often resulting in the dreaded "0 byte file" problem.
The biggest issue here I think is the way your sending the file, have you tried sending in within chunks:
if (file_exists($zip_file))
{
header('Content-type: application/zip');
header('Content-disposition: filename="' . $zip_name . '"');
header("Content-length: " . filesize($zip_file));
$resource = fopen($zip_file,'r');
while(!feof($resource))
{
$chunk = fread($resource,4096);
//....
echo $chunk;
}
exit();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With