我有一个 zip 功能,我希望 FOLDER 中的每个文件都可以压缩
所以,路径是:
public_html/form/FOLDER/file_to_zip.xml
正如您在下面的代码中看到的那样,$files_to_zip 数组具有“FOLDER/file_to_zip.xml”路径,每当它压缩时,也会压缩文件夹,我只想压缩文件。
我可以在这里做什么?
function create_zip($files = array(),$destination = '',$overwrite = true) {
$valid_files = array();
if(is_array($files)) {
foreach($files as $file) {
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
if(count($valid_files)) {
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
$zip->close();
return file_exists($destination);
}
else
{
return false;
}
}
$loja=$_GET['loja'];
$connect = new MySQL('localhost','iloja_phc','sexparade');
$connect->Database('iloja_phc');
$posts = $connect->Fetch('ipad');
if ($posts && mysql_num_rows($posts) > 0) {
echo "Nome - ID - Email:<BR>";
while ($record = mysql_fetch_array($posts)) {
$files_to_zip = array($loja.'/CL'.$record['rand'].'.xml');
$result = create_zip($files_to_zip,'CL'.$record['rand'].'.zip');
echo "<a href='/formulario/CL".$record['rand'].".zip'>".$record['nome']."</a> - ".$record['id']." - EMAIL: ".$record['email']."</br>";
}
} else {
echo "Erro! Algo correu mal...";
}