Log in

View Full Version : zip format is not downloading



hemi519
01-15-2011, 10:31 PM
Hi All,

i written a code such that user will download a zip from link and he can not no the link he is downloading from. This is my code

$filename = "movies.zip";
$path = "downloads";
header("Content-Type:application/zip");
header("Content-Length: ".filesize($path."/".$filename));
header('Content-Disposition: attachment; filename="'.$filename.'"');
$file = fopen($path."/".$filename, "r");
while(!feof($file)) {
$buf = fread($file, 4096);
echo $buf;
}

The link will be given in the other page which redirects to this page. It starts downloading the file as soon as user clicks on it . But after some time it stops and displays this error

End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.

If i give the direct location using header function in PHP . It downloads full but i dont want in that way

fileserverdirect
01-17-2011, 04:12 PM
Quick googling found this:


<?
$dir="downloads/";
if (isset($_REQUEST["file"])) {
$file=$dir.$_REQUEST["file"];
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file));
header("Content-disposition: attachment; filename="".basename($file).""");
readfile("$file");
} else {
echo "No file selected";
}
?>

Just goto download.php?file=movies.zip.
*Untested, you may have to change the headers....

Oziam
01-22-2011, 07:35 AM
or;


$filename = "movies.zip";
$path = "downloads";
$file = fopen($path."/".$filename, "r");

header("Pragma: public");
header("Expires: 0");
header("Cache-control: private");
header("Content-Type: application/x-zip-compressed");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($path."/".$filename));
header('Content-Disposition: attachment; filename="'.$filename.'"');

while(!feof($file)){
print stream_get_contents($file);
//print fread($file, 4096);
}
fclose($file);

notice I added;
header("Content-Type: application/x-zip-compressed");

header("Content-Type:application/zip"); is incorrect.

hemi519
02-04-2011, 01:29 PM
I tried it, but it is still giving me the same error