【问题标题】:I am trying to Download Multiple images as a zip folder but getting error using laravel 7我正在尝试将多个图像下载为 zip 文件夹,但使用 laravel 7 时出错
【发布时间】: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


    【解决方案1】:

    如果你愿意,试试这个:

    $zipFile = $folderName.'.zip';
    

    您的根目录已经在公用文件夹中,因此它会尝试将路径添加到公用文件夹。那是不存在的。这就是您收到错误的原因。

    或者您可以尝试添加公用文件夹中的文件夹,例如

    'uploads/images/58-Digitizing-logo/' . $folderName . '.zip';
    

    【讨论】:

      猜你喜欢
      • 2020-10-19
      • 2020-11-11
      • 2021-01-18
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      • 1970-01-01
      • 2015-10-25
      相关资源
      最近更新 更多