Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zip File Download Problem 1

Status
Not open for further replies.

jay123454

Programmer
Jun 15, 2001
46
US
Hi,

Been banging my head against the wall for a few hours now...hopefully someone can help me out.

I've got a zip file that works fine when I unzip it locally or when I do a direct download. But when I try to download the same exact file with a php download script I can't extract the zip file.

The filesizes of the two files are exactly the same.
3,775,998 bytes for the "Good" file that I upload and the "Corrupt" file that I download using the php download script.

Here is the error I'm getting from Winzip (Also getting an error with WinRar).
"End-of-central-directory signature not found. Either this file is not a Zip file, or it constitutes one disk of a multi-part Zip file."

Here is the code I am using.


$filename=$DOWNLOAD_FILE_PATH;
$filename = realpath($filename);

$file_extension = strtolower(substr(strrchr($filename,"."),1));

switch ($file_extension) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpe": case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}

if (!file_exists($filename)) {
die("NO FILE HERE");
}

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($filename));
set_time_limit(0);
@readfile("$filename") or die("File not found.");
 
what happens if you download it with the Content type as application/force-download ? also i'd suggest you remove the error supressor in front of the readfile statement until you're sure it's working ok.


i don't think set_time_limit is likely to be useful here as the script itself is very short. the php timeouts don't apply/count in stream operations and the like.
 
That's what I had had at first "application/force-download". Strange issue with that in Firefox in that firefox said it was a "JPEG Image" type in the Firefox downloader.

So I hardcoded it as "application/zip" and the type was correct in firefox.
However it never worked in either Firefox or IE.

Anyways, just changed the type to application/force-download and remove the @ error surpression.

No error & same thing...seemed to download fine. Exact same file size as the original but it won't extract with WinZip or WinRar.

Any other ideas?

 
Hey jpadie!

Thanks for the help..but I'm an idiot. Just figured out the problem :)

I had some php code above the download script to determine which file to download and if the person had access to it. There was an undefined function error in that code that I wasn't seeing. However, put a die above the download script and saw it...fixed that and it solved the problem!

Thanks!
jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top