简体   繁体   English

在Laravel 5.3上下载文件

[英]Downloading file on Laravel 5.3

I'm trying to download a zip generated file but I'm getting a FileNotFoundException , this is the code: 我正在尝试下载一个zip生成的文件,但我得到一个FileNotFoundException ,这是代码:

    $zipper = new \Chumper\Zipper\Zipper;

    foreach($request->values as $id_post){
        $post = Post::find($id_post);
        $imagenes[] = public_path().'/uploads/posts/'.$post->imagen;
    }
    $nombreZip = 'test'.time().'.zip';
    $rutaZip = (public_path().'/zips/'.$nombreZip);
    $zipper->make($rutaZip)->add($imagenes);
    return (response()->download($rutaZip, 'posts.zip'));

I have already checked the file route that returns and the file is right there, with the same name and everything. 我已经检查了返回的文件路由,文件就在那里,具有相同的名称和所有内容。 Any ideas? 有任何想法吗?

Try this: 尝试这个:

$zipper = new \Chumper\Zipper\Zipper;

foreach($request->values as $id_post){
    $post = Post::find($id_post);
    $imagenes[] = 'public/uploads/posts/'.$post->imagen;
}
$nombreZip = 'test'.time().'.zip';
$rutaZip = (public_path().'/zips/'.$nombreZip);
$zipper->make("public/zips/{$nombreZip}")->add($imagenes);
return (response()->download($rutaZip, 'posts.zip'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM