在Laravel 5.3上下载文件

时间:2017-01-18 18:13:58

标签: php laravel file download

我正在尝试下载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'));

我已经检查了返回的文件路由,文件就在那里,具有相同的名称和所有内容。有任何想法吗?

1 个答案:

答案 0 :(得分:0)

试试这个:

$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'));