Zip File Corrupted When Downloaded using PHP Downloader

Posted in Web Development on 7 November 2009 2 comments

If you are using a downloader script to provide download and the downloaded zip file is corrupted, don’t panic, follow the steps below.

1. Try download the zip file using the real URL

It is possible that your zip file is not uploaded completely. In my case, I uploaded 2 zip files via FTP software and they actually corrupted itself. Then I wasted 2 hours looking for solution using Google.

2. Make sure there is no other output in your downloader script

The script should only output the content zip file. Even an extra space character might cause problem.

Another possibility is : Byte Order Mark – BOM exists in your download script file. To ensure BOM doesn’t exist, open the file using NotePad++, click Format > Encode in UTF-8 Without BOM

3. Compare the header strings

Still not working? The problem might be in your header() strings. Compare your header strings with this.

$filename = 'path_to_your_file.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: application/zip'); 
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($filename) );

4. Contact your host

If it is still not working, contact your host and explain your problem to them.

 

Posted by Zen on 7 November 2009 • 9,933 visits 2 comments
Tags :


or Subscribe to specific category only :




  - 2 Comments


Hanan Ali says:

I was fed up by the script i used and i found almost the same script in all forums and by chance i visit you site and after reading first point i downloaded the zip file by ftp and xtract that and come to know that zip file is not being uploaded perfectally to my server. So many thanks buddy :)

Behnam says:

This part saved the day for me:

Even an extra space character might cause problem.

Many thanks

Leave a Reply

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Previous Post
«
Next Post
»