开发者

PHP : problem rendering zip file

开发者 https://www.devze.com 2023-03-11 11:38 出处:网络
header(\"Content-type: application/zip\"); $contents=file_get_cont开发者_如何学Cents($the_file);
header("Content-type: application/zip");
$contents=file_get_cont开发者_如何学Cents($the_file);
echo "$contents";
exit;

The file is about 40 MB. But, on downloading, size is only few hundred bytes. Please help!


Try to set Content-Length:

header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="file.zip"');


The comments are correct; it's very likely an error message that will be easily ascertained by opening the file in a text editor. I'd like to also offer that you could use the readfile function to greater effect. See the first example for some good code with headers that gives you a good download. Plus, it'll shorten your code by a line. http://php.net/manual/en/function.readfile.php

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号