【问题标题】:Laravel Chumper Zipper close() not creating zip fileLaravel Chumper Zipper close() 不创建 zip 文件
【发布时间】:2016-12-09 04:45:03
【问题描述】:

我正在尝试创建一个包含文件夹的 zip 文件。 现在代码是:

{
$zipper = new \Chumper\Zipper\Zipper;
$zipper->make(storage_path('app/' . $zipPath));
.
.
Storage::makeDirectory($zipPath . DIRECTORY_SEPARATOR . $user->username , 0777);
$zipper->folder($zipPath . DIRECTORY_SEPARATOR . $user->username);
$currentZipPath = $zipPath . DIRECTORY_SEPARATOR . $user->username;
Storage::makeDirectory($currentZipPath . DIRECTORY_SEPARATOR . $myfolder->name , 0777);
                        $zipper->folder($currentZipPath . DIRECTORY_SEPARATOR . $myfolder->name);
.
.
$this->addDataToZip($contents, $currentZipPath . DIRECTORY_SEPARATOR . $myfolder->name,  $zipper, $user);

Log::info('Zip status : ' . $zipper->getStatus());  //Gives "No error"
$zipper->close();
}


public function addDataToZip($contents, $path, &$zipper, $user)
 {



foreach ($contents as $content) {
 $filebasepath = storage_path('app/' . $path);

 Storage::copy(
      $this->model->getActiveStorageBasePath($user)
             . DIRECTORY_SEPARATOR . $content->unique_name,
      $path . DIRECTORY_SEPARATOR . $content->unique_name
 );

$zipper->add(storage_path() . DIRECTORY_SEPARATOR . 'app'
                    . DIRECTORY_SEPARATOR . $path
                    . DIRECTORY_SEPARATOR . $content->unique_name);
}
}

现在,当我在本地查看文件夹时,将创建具有完整层次结构和内容的 entie admin.zip 文件夹。 但是在 $zipper->close 上,不会创建 zip 文件,并且 admin.zip 文件夹仍然存在。 API 调用或日志中也没有错误。 请指导我可能在哪里出错

【问题讨论】:

    标签: php laravel file zip ziparchive


    【解决方案1】:

    参见示例Chumper/Zipper。这是简单直接的使用方式。

    或者您可以将此行 "status ::". $zipper->status . "\n" 放在 $zipper->add() 之后以检查状态。

    【讨论】:

    • 获取:$status 未找到。对于 $zipper->getStatus(), [2016-12-09 12:05:19] local.INFO: status ::No error , 对于每个 $zipper->add
    • 检查此路径是否正确? print storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $content->unique_name;
    • 它显示正确的路径...原始文件的实际绝对路径
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    • 2022-06-11
    • 2015-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多