2014-04-29 18 views
0

我嘗試在我的laravel web項目中下載選項。 代碼1:從服務器上的laravel網頁下載任何文件類型

public function downloadLogo() 
{ return Response::download(images/logo.png); } 

代碼2:

$file = public_path()."/images/logo.png"; 
$headers = array('Content-Type: application/png',); 
return Response::download($file, 'logo.png',$headers); 

他們沒有工作。任何想法?

+0

無論你的代碼應及時下載,除了第一個代碼路徑放在引號「圖像/ logo.png 「,您是否確定該圖像實際上是可訪問的(通過使用您的瀏覽器訪問它,例如 /images/logo.png),或者該應用程序返回任何錯誤? – har2vey

+0

圖像可訪問 – Racoon

回答

0
Try this, 

     $file = "images/logo.png"; 
     $headers = array('Content-Type'=>'application/png'); 
     return Response::download($file, 'logo.png',$headers); 
+0

不,沒有.. – Racoon

1

也許爲時已晚,但這裏是實現這一目標的正確方法:

return Response::download($file , 'logo.png' , array('Content-Type' => 'image/png'))->setContentDisposition('inline'); 
相關問題