首页 > 解决方案 > ZipArchive 的路径在哪里?

问题描述

我正在尝试通过将文件添加到 zip 并在下载时返回响应来进行文件的多次下载。但是zip的路径是什么?

use Illuminate\Support\Facades\Response as FacadeResponse;

$pdfs = $request->get('check');

        if (is_array($pdfs)) {
            $zipname = "facturas.zip";
            $zip = new \ZipArchive();
            $zip->open($zipname, \ZipArchive::CREATE);
            foreach ($pdfs as $pdf) {
                $zip->addFile($pdf);
            }
            $zip->close();

            $headers = array(
            'content-type' => 'application/zip',
            'Content-disposition:' => 'attachment; filename=filename.zip'
            );

            $path = ???

            return FacadeResponse::download($path, $zipname, $headers);
        }

我已经尝试过使用 base_path。public_path, app_path ...但没有一个有效。

标签: laravelzipziparchive

解决方案


推荐阅读