【发布时间】:2021-07-26 08:24:22
【问题描述】:
我正在尝试将多个图像下载为一个 zip 文件夹,但不幸的是我遇到了错误,请帮助我如何解决这个问题,谢谢。
出现错误
文件“/home/developer/htdocs/yourstitchart.com/cms/public/uploads/images/58-Digitizing-logo/58-Digitizing-logo.zip”不存在
请查看https://flareapp.io/share/87ngoJ65
收件箱控制器
public function dowloads($id)
{
$url = config('yourstitchart.file_url');
$zip = new ZipArchive;
$inboxFiles = Inbox::where('id', $id)->first()->file;
$files = [];
foreach (json_decode($inboxFiles) as $file) {
$files[] =$url. $file;
}
$inbox = Inbox::find($id);
$folderName = $inbox->id.'-'.str_replace(' ', '-',$inbox->order_name);
$zip = new ZipArchive;
$zipFile = $url .$folderName.'/'.$folderName.'.zip';
if ($zip->open($zipFile, ZipArchive::CREATE) === TRUE)
{
//add files into a zip
foreach ($files as $key => $value) {
$relativeNameInZipFile = str_replace('full',$key,basename($value));
$zip->addFile($value, $relativeNameInZipFile);
}
$zip->close();
}
return response()->download($zipFile);
}
HTML 视图
<td>
@if($digitizingInbox->file)
<a href="{{ route('download.inbox',$digitizingInbox->id) }}"
class="download btn btn-warning">Download
</a>
@endif
</td>
【问题讨论】:
标签: laravel