downloading zip using php
Posted: Mon Apr 11, 2011 7:44 pm
have been trying to set up an area in a registered user only area of a site, have found many scripts to start a download without showing the actual area where the file resides, but the one thing I can't seem to get fixed is getting the zip file which is downloaded either not to be corrupted or simply empty.
No matter what I try, it is always empty or corrupted.
here is the code which returns a zip without any content:
I thought the ob_start and the ob_end_clean would resolve this, but it really is a hassle for me.
This is the second time I've posted on these forums because I tend to google the answer, I much rather spend hours and hours trying and testing to resolve my problems rather than posting a noob question (designer with very basic php skills) and wasting the time of so many who help others, but in this case, I just can't seem to get that zip downloaded correctly.
I have tested on Linux, OSx, WIn, and every browser from IE7 to 9, current versions of FF, Op, Saf, Chrome all the same, the file downloads, it even extracts, but there isn't anything in it. I have made sure several times, the path is correct and that the zip actually DOES contain a test file. Have also tried to use http in the file path, does the same thing.
Any help, as always, is highly appreciated
No matter what I try, it is always empty or corrupted.
here is the code which returns a zip without any content:
Code: Select all
<?php
ob_start();
$path = '/site/site_files/download_files/test.zip';
$mm_type="application/zip";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
ob_end_clean();
readfile($path); // outputs the content of the file
exit();
?>
This is the second time I've posted on these forums because I tend to google the answer, I much rather spend hours and hours trying and testing to resolve my problems rather than posting a noob question (designer with very basic php skills) and wasting the time of so many who help others, but in this case, I just can't seem to get that zip downloaded correctly.
I have tested on Linux, OSx, WIn, and every browser from IE7 to 9, current versions of FF, Op, Saf, Chrome all the same, the file downloads, it even extracts, but there isn't anything in it. I have made sure several times, the path is correct and that the zip actually DOES contain a test file. Have also tried to use http in the file path, does the same thing.
Any help, as always, is highly appreciated