2 回答

TA貢獻2037條經(jīng)驗 獲得超6個贊
看看 Laravel Helpers 文檔:http ://laravel.com/docs/4.2/helpers
如果您想要鏈接到您的資產(chǎn),您可以這樣做:
$download_link = link_to_asset('file/example.png');
如果上述方法對您不起作用,那么您可以在app/routes.php 中實現(xiàn)一個相當簡單的下載路由,如下所示:
請注意,此示例假設(shè)您的文件位于app/storage/file/位置
// Download Route
Route::get('download/{filename}', function($filename)
{
// Check if file exists in app/storage/file folder
$file_path = storage_path() .'/file/'. $filename;
if (file_exists($file_path))
{
// Send Download
return Response::download($file_path, $filename, [
'Content-Length: '. filesize($file_path)
]);
}
else
{
// Error
exit('Requested file does not exist on our server!');
}
})
->where('filename', '[A-Za-z0-9\-\_\.]+');
用法:http: //your-domain.com/download/example.png
這將在以下位置查找文件:app/storage/file/example.png(如果存在,將文件發(fā)送到瀏覽器/客戶端,否則將顯示錯誤消息)。
PS'[A-Za-z0-9\-\_\.]+此正則表達式確保用戶只能請求名稱包含 A-Z或a-z(字母)、0-9(數(shù)字)-或_或.(符號)的文件。其他所有內(nèi)容都被丟棄/忽略。這是一項安全/安保措施......

TA貢獻1824條經(jīng)驗 獲得超5個贊
為了獲得 Media 模型,我所要做的就是更改以下內(nèi)容
$mediaItem = $mediaCollection->where('id', $mediaItemId);
到
$mediaItem = $mediaCollection->where('id', $mediaItemId)->first();
- 2 回答
- 0 關(guān)注
- 178 瀏覽
添加回答
舉報