www.webdeveloper.com
Results 1 to 5 of 5

Thread: Invalid Zip file

  1. #1
    Join Date
    Feb 2012
    Posts
    102

    Question Invalid Zip file

    Can anyone help me figure out why when I download a zip file with headers in php it is invalid? The file opens fine on my server but when I test my download code and save the file to my desktop it says it is invalid. What could be causing this? Here is the code I am using to download the zip file:
    PHP Code:
    if (file_exists ($file)) {     
            
    header('Pragma: public');
            
    header('Expires: 0');
            
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            
    header('Content-Description: File Transfer');
            
    header('Content-type: application/octet-stream');
            
    header('Content-Disposition: attachment; filename=' .basename($file));
            
    header('Content-Transfer-Encoding: binary');
            
    header('Content-Length: '.filesize($file));
            
    ob_clean();
            
    flush();
            
    readfile($file);
            exit(); 
    // Stop the page.
        

    Any Suggestions?

  2. #2
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    You might try these functions;

    zip_open()

    or

    zip_read()

  3. #3
    Join Date
    Feb 2012
    Posts
    102
    When I remove the ob_clean() it works. I am a little new to php so does that function have any security issues I should be concerned about? Also, is there something that would cause the rest of the page to not be output after the readfile()? For some reason the download is working fine but the message and footer I have placed on the page after the headers are not being output. The exit function in the above code is moved down after the message and footer.
    Last edited by mcco; 05-15-2012 at 10:13 AM.

  4. #4
    Join Date
    Oct 2012
    Posts
    1
    In your case following program method must be useful Fix zip file tool may restore your zip archives in cases: ZIP file you have been downloading for so long is broken, corrupt and cannot be opened and others.

  5. #5
    Join Date
    Mar 2009
    Posts
    452
    try to move ob_clean() and flush() before the first header. i think your file is output empty.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles