The method "add" is for when your appending files to an existing zip file, the method you need to use is "create". See if the code below works for you
PHP Code:
// Set the directory
$dir = "A Flat";
$fileList = array();
if (is_dir($dir)){
if ($open = opendir($dir)){
while(false !== ($read = readdir($open))){
if ($read != '.' && $read != '..'){
echo $read." - File Size: ".filesize($dir."/".$read)." bytes<br />";
$fileList[] = $read;
}
}
} else {
echo "Unable to open the directory at \"$dir\"";
}
} else {
echo "The directory ( $dir ) is not a valid path!";
}
// Make sure the array is at least "1" value
if (sizeof($fileList) > 0){
// Include the PCLZip class
include_once('pclzip.lib.php');
// Create a new instance of the class
$archive = new PclZip('mp3_files.zip');
// Build a list of the files
$files = implode(', ', $fileList);
// Add the files to the archive
$v_list = $archive->create($files);
// Finish up
if ($v_list == 0){
die("Error : ".$archive->errorInfo(true));
} else {
header('Location: mp3_files.zip');
}
}
Bookmarks