Created
March 7, 2019 11:17
-
-
Save ekam230/bdb53c6ba786fa93378a4fa840ef1c3c to your computer and use it in GitHub Desktop.
Download Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//только авторизованный пользователь может скачать файл | |
Route::group(['middleware' => 'auth'], function () { | |
//обращаемся к маршруту /download?f=path | |
Route::get('download', function () { | |
//получаем GET запрос | |
$path = request('f'); | |
//смотрим на расширение запрашиваемого файла | |
$extension = pathinfo($path, PATHINFO_EXTENSION); | |
//создаем массив расширений файлов запрещенных к скачиванию | |
$blocked = ['php', 'htaccess']; | |
//если расширение запрашиваемого файла отсутствует в массиве выше | |
if (! in_array($extension, $blocked)) { | |
//скачиваем этот файл | |
return response()->download($path); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment