dongyi8416 2016-08-12 22:53
浏览 96

下载zip文件laravel 5.2

Gettin this error when im trying to download zip file

The file "C:\wamp\www\Petro\public\download/downloads.zip" does not exist

My code

if (\File::exists('download/downloads.zip')) {
     $directory = public_path('download');
     $success   = \File::cleanDirectory($directory);

       foreach($checked as $check){
        $path = File::where('name',$check)->select('real_path')->first();
        $img = \Image::make($path->real_path);
        $img->save(public_path('download'). '/'. $check);
       }

   } else {
       foreach($checked as $check){
        $path = File::where('name',$check)->select('real_path')->first();
        $img = \Image::make($path->real_path);
        $img->save(public_path('download'). '/'. $check);
     }
  }

       $files = \File::files('download');
       \Zipper::make('download/downloads.zip')->add($files);
       $pathtoFile = public_path('download/downloads.zip');
       return response()->download($pathtoFile);

The zip is created but i cant download it, what is wrong with my code?

When i use dd($files) after create the zip :

array:4 [▼
  0 => "download/batman.jpg"
  1 => "download/batmanfamily.jpg"
  2 => "download/batwoman.jpg"
  3 => "download/daredevil.jpg"
]

There is not zip file but if i check in my local directory the zip is created. Can you guys give me a hand with this and sorry for the bad english.

  • 写回答

2条回答 默认 最新

  • doufu1970 2016-08-12 23:27
    关注

    As you can see in your error you have / instead of \ this.

    The file "C:\wamp\www\Petro\public\download/downloads.zip" does not exist
                                               ^
                                              Here
    

    change / in following line to \:

     $pathtoFile = public_path('download/downloads.zip');
    

    To

     $pathtoFile = public_path('download\downloads.zip');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大