Results 1 to 4 of 4

Thread: zip format is not downloading

  1. #1
    Join Date
    Nov 2010
    Posts
    115
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default zip format is not downloading

    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
    Last edited by hemi519; 01-15-2011 at 10:37 PM.

  2. #2
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Quick googling found this:
    PHP Code:
    <? 
    $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....
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  3. #3
    Join Date
    Jan 2011
    Location
    QLD, Australia
    Posts
    23
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    or;

    PHP Code:
    $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.

  4. #4
    Join Date
    Nov 2010
    Posts
    115
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default

    I tried it, but it is still giving me the same error

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •