2017-09-13 78 views
0

我有以下功能下载PDF文件下载后如何重定向?

public function download($id) { 
     $detail = pesanmakam::findOrFail($id); 
     $name = date('YmdHis') . ".pdf"; 
     $data = PDF::loadView('guest/log/pdf', compact('detail'))->setPaper('a4')->setWarnings(false)->save('myfile.pdf'); 
     return $data->download($name); 
    } 

上面下载功能工作正常,但它只是停留在同一页上。下载成功后可以将其重定向到另一个页面吗?

+1

https://stackoverflow.com/questions/25624927/how-do-i-redirect-after-download -in-laravel 按照这个URL这将帮助你,我认为 –

+0

你可以使用 Redirect :: to('/ otherpage'); – Abhishek

+0

[PHP生成文件下载然后重定向]的可能重复(https://stackoverflow.com/questions/822707/php-generate-file-for-download-then-redirect) –

回答

0

Read it

public function download($id) { 
     $detail = pesanmakam::findOrFail($id); 
     $name = date('YmdHis') . ".pdf"; 
     $data = PDF::loadView('guest/log/pdf', compact('detail'))->setPaper('a4')->setWarnings(false)->save('myfile.pdf'); 
     // return $data->download($name); 
     return Redirect::to($url);//$url > where u want to go 
    } 
0

只是函数调用后以下行粘贴

header('Location: http://www.example.com/'); 

假设你调用的函数一样

$down = download(10); 
//then just below it write like 
header('Location: http://www.example.com/'); 

,而不是http://www.example.com把页面的URL,其中您想下载后重定向。

1

您不能因为强制下载文件是由HTTP标头创建的,并且重定向是基于相同的。所以你不能同时做两个。

你可以找到关于这个其他主题的更多信息here

0

试试这个:

public function download($id) { 
     $detail = pesanmakam::findOrFail($id); 
     $name = date('YmdHis') . ".pdf"; 
     $data = PDF::loadView('guest/log/pdf', compact('detail'))->setPaper('a4')->setWarnings(false)->save('myfile.pdf'); 
     $data->save('folder_name/'.$name) 
     return Redirect::to('url') 
    }