我将使用 PHP 类创建一个 Zip 存档。但它仍然无法正常工作。 它不会失败,响应是 1。他没有创建 Zip 文件。
$zip = new ZipArchive;
$res = $zip->open('qr_img/'.'ab387bas.zip'.'', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFile($file, 'screen.png');
$zip->close();
}
每个人都知道答案吗?
最佳答案
$file_names
是您要添加到 zip 中的文件数组。
function zipFile($file_names,$archive_file_name)
{
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::OVERWRITE )!==TRUE) {
}
//add each files of $file_name array to archive
foreach($file_names as $files)
{
// $zip->addFile($files,$files);
$zip->addFromString(basename($files), file_get_contents($files));
}
$zip->close();
}
关于php - ZipArchive 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23241725/