I have written a PHP script that automatically begins the download of a ZIP file when a user goes to the page. I created the ZIP file with XP's built-in archiver (Right-click the files, Send To -> Compressed Folder). This ZIP file extracts fine on my PC, and it extracts fine if the users access it by going directly to its URL (i.e., http://www.mysite.com/file.zip
However, if they go to the PHP script that launches the automatic download (i.e., http://www.mysite.com/download.php
they can't open the ZIP file. When they try to extract the ZIP, they get an error message that says:
"Compressed (zipped) Folders Error
Windows cannot open the folder.
The Compressed (zipped) Folder: 'C:\Downloads\file.zip' is invalid."
On Windows XP, it's a similar error message that says the compressed folder is invalid or corrupted. Any ideas what the problem is? It's strange how it works fine if they download the file directly.
$fpath = 'cdl/client.zip';
if( $_SESSION['psys']['logged'] == true )
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: application/zip' );
header( 'Content-Disposition: attachment; filename="' . basename( $fpath ) . '";' );
header( 'Content-Transfer-Encoding: binary' );
header( 'Content-Length: ' . filesize( $fpath ) );
readfile( $fpath );
header( 'Location: index.php' );