首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ZipArchive失败

ZipArchive失败
EN

Stack Overflow用户
提问于 2014-04-23 10:34:25
回答 1查看 1.1K关注 0票数 0

我将使用PHP类创建。但还是不起作用。它不会失败,响应是1。他不会创建Zip。

代码语言:javascript
复制
$zip = new ZipArchive;
$res = $zip->open('qr_img/'.'ab387bas.zip'.'', ZipArchive::CREATE);
if ($res === TRUE) {
    $zip->addFile($file, 'screen.png');
    $zip->close();
}

大家都知道答案吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-23 12:10:13

$file_names是要在zip中添加的文件数组。

代码语言:javascript
复制
 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();


}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23241725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档