【发布时间】:2019-10-02 11:47:38
【问题描述】:
编辑
问题解决了。必须更新我的文件系统配置。
我想创建一个 zip 文件,其中包含之前生成的所有发票。问题是,如果我尝试使用 laravel 存储 url() 或 get() 函数,ZipArchive 找不到文件。
我尝试使用storage_path()、->url()、->get() 解决它,但它们都不起作用。它仅在我输入文件路径时才有效。
这就是它现在的样子,并且可以正常工作。
$invoiceZipFileName = Carbon::now()->toDateString() . "_invoices.zip";
$zip = new ZipArchive();
$zip->open($invoiceZipFileName, ZipArchive::CREATE);
$files->each(function ($item, $key) use ($zip, $disk) {
$zip->addFile("storage/invoices/" . $item, $item);
});
$zip->close();
我想要实现的是这样的:
$invoiceZipFileName = Carbon::now()->toDateString() . "_invoices.zip";
$zip = new ZipArchive();
$zip->open($invoiceZipFileName, ZipArchive::CREATE);
$files->each(function ($item, $key) use ($zip, $disk) {
$zip->addFile($disk->get($item), $item);
});
$zip->close();
或:
$invoiceZipFileName = Carbon::now()->toDateString() . "_invoices.zip";
$zip = new ZipArchive();
$zip->open($invoiceZipFileName, ZipArchive::CREATE);
$files->each(function ($item, $key) use ($zip, $disk) {
$zip->addFile($disk->url($item), $item);
});
$zip->close();
或:
$invoiceZipFileName = Carbon::now()->toDateString() . "_invoices.zip";
$zip = new ZipArchive();
$zip->open($invoiceZipFileName, ZipArchive::CREATE);
$files->each(function ($item, $key) use ($zip, $disk) {
$zip->addFile(storage_path("invoices") . "/" . $item, $item);
});
$zip->close();
这些是错误消息(每个都是在另一种情况下,它们不会一起出现)我得到:
exception: "Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException"
file: "C:\xampp\htdocs\invoicing\vendor\symfony\http-foundation\File\File.php"
line: 36
message: "The file "2019-10-02_invoices.zip" does not exist"
exception: "ErrorException"
file: "C:\xampp\htdocs\invoicing\app\Http\Controllers\Api\V1\InvoiceController.php"
line: 211
message: "ZipArchive::close(): Failure to create temporary file: No error"
++++ 编辑 ++++ 问题解决了。必须更新我的文件系统配置。
【问题讨论】:
标签: laravel storage filepath ziparchive laravel-storage