Zip
Moderator: General Moderators
This code is not working for me.
I use windows.
Code: Select all
<?PHP
// this script zips up a directory (on the fly) and delivers it
// C.Kaiser 2002
// No Copyright, free to use.
// get the filename of this php file without extension.
// that is also the directory to zip and the name of the
// zip file to deliver
$filename_no_ext=str_replace(".php","",basename($SCRIPT_NAME));
// we deliver a zip file
header("Content-Type: archive/zip");
// filename for the browser to save the zip file
header("Content-Disposition: attachment; filename=$filename_no_ext".".zip");
// get a tmp name for the .zip
$tmp_zip = tempnam ("tmp", "tempname") . ".zip";
// zip the stuff (dir and all in there) into the tmp_zip file
`zip -r $tmp_zip $filename_no_ext`;
// calc the length of the zip. it is needed for the progress bar of the browser
$filesize = filesize($tmp_zip);
header("Content-Length: $filesize");
// deliver the zip file
$fp = fopen("$tmp_zip","r");
echo fpassthru($fp);
// clean up the tmp zip file
`rm $tmp_zip `;
?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
You have parse errors,
You need to pass this line through exec(), although you may want to pass those variables through escapeshellarg() to escape any nasty characters.
Code: Select all
// zip the stuff (dir and all in there) into the tmp_zip file
`zip -r $tmp_zip $filename_no_ext`;I have changed the code to
Error:
The archive is unknown format or damaged
Code: Select all
$filename_no_ext=str_replace(".php","",basename($SCRIPT_NAME));
// we deliver a zip file
header("Content-Type: archive/zip");
// filename for the browser to save the zip file
header("Content-Disposition: attachment; filename=$filename_no_ext".".zip");
// get a tmp name for the .zip
$tmp_zip = tempnam ("tmp", "tempname") . ".zip";
// zip the stuff (dir and all in there) into the tmp_zip file
exec(`zip -r $tmp_zip $filename_no_ext`);
// calc the length of the zip. it is needed for the progress bar of the browser
$filesize = filesize($tmp_zip);
header("Content-Length: $filesize");The archive is unknown format or damaged