going through the code i understand that this part is only to force the dialog box to open
CODE
$buffer = file_get_contents($filename);
/* Force download dialog... */
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
/* Don't allow caching... */
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
/* Set data type, size and filename */
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . strlen($buffer));
header("Content-Disposition: attachment; filename=$filename.zip");
/* Send our file... */
echo $buffer;
so this part in theory should put the files into the zip folder right?
CODE
$files_to_zip = array(
'upload_test/2009-07-01-214005_Logo.jpg',
'upload_test/2009-07-01-215314orange_bg.gif',
'upload_test/2009-07-01-215326emptycart.gif',
'upload_test/2009-07-01-223317dash.gif',
'upload_test/2009-07-02-020536arrow.gif',
'upload_test/2009-07-02-020717check_green.gif'
);
//if true, good; if false, zip creation failed
$result = create_zip($files_to_zip,'my-archive.zip');
/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
//close the zip -- done!
$zip->close();
//check to make sure the file exists
return file_exists($destination);
}
else
{
return false;
}
}
now i know the images are hard coded in there which is not what i want to do. but this gives me the same error as the first one. does anyone know what is wrong with the code. and possibly if they know how to put the files into the array dynamically?
This post has been edited by NeekWorld: 3 Jul, 2009 - 11:33 AM