2017-09-13 37 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') 
    }