1 頁 (共 1 頁)

How to create download link in Laravel

發表於 : 2016-06-16 23:13:00
yehlu
http://stackoverflow.com/questions/2697 ... in-laravel

代碼: 選擇全部

// 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\-\_\.]+');