Created
May 23, 2020 09:01
-
-
Save megabayt/b2498c9c3568d5f5d59617290f7681de to your computer and use it in GitHub Desktop.
Временная ссылка
This file contains 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
// Генерация временной ссылки | |
$this->say( | |
"Вот ссылка на файл ".$file->name.":\n". | |
URL::temporarySignedRoute( | |
'download', | |
now()->addMinutes(2), | |
['file' => $file->id] | |
). | |
"Ссылка будет действовать 2 минуты" | |
); | |
// Валидация временной ссылки | |
class DownloadController extends Controller | |
{ | |
public function download(Request $request) { | |
if (!$request->hasValidSignature()) { | |
echo "Время жизни ссылки истекло"; | |
} | |
$file = File::find($request->file); | |
return response()->streamDownload(function () use ($file) { | |
echo file_get_contents($file->url); | |
}, $file->name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment