tanon
tanon

Reputation: 13

PHP : problem rendering zip file

header("Content-type: application/zip");
$contents=file_get_contents($the_file);
echo "$contents";
exit;

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

Upvotes: 0

Views: 165

Answers (2)

Bob Baddeley
Bob Baddeley

Reputation: 2262

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

Upvotes: 0

Michael Spector
Michael Spector

Reputation: 37019

Try to set Content-Length:

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

Upvotes: 3

Related Questions