php - ZipArchive 失败

标签 php html mysql css

我将使用 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/

相关文章:

mysql - 如何在一个查询中组合多个 SUM?

mysql - 如何在条件下使用同一表中的数据有条件地从表中删除行?

php - 对于死链接,我们应该考虑哪些 HTTP 状态代码

php - 获取用户的所有帖子及其类别

javascript - Cordova 后退按钮不起作用

javascript - 如何在焦点上显示占位符文本?

mysql - 模拟mysql查询

php - PDO 准备在单个查询中插入多行

php - Woocommerce 注册中的附加用户角色选择字段

javascript - 如何使用 pdf.js 确定 pdf 的大小以便我可以缩放到屏幕大小?