The following is the [Extended recommendation] laravel-download-link (generate download link) tutorial column to introduce laravel-download-link (generate download link) to everyone, I hope it will be helpful to friends in need!
This extension allows you to generate download links for files.
After installation, you can perform the following operations:
$link = DownloadLink::disk('public')->filePath('uploads/test.txt')->generate(); // zkTu70fieUFZLGMoEP95l1RQfFj5zCOqHlM0XBTnc6ZaZTtm4GY5xPXGGLzLEAVe
The default download route in the configuration file is "download", so if your domain name is "example.com", you should use this Link:
example.com/download/{link}// 例如 example.com/download/zkTu70fieUFZLGMoEP95l1RQfFj5zCOqHlM0XBTnc6ZaZTtm4GY5xPXGGLzLEAVe
Note: You need to replace {link}
with the generated link.
You can publish the configuration file using the following command:
php artisan vendor:publish --provider="Armancodes\DownloadLink\DownloadLinkServiceProvider" --tag="config"
This is the content of the published configuration file:
return [ /* |-------------------------------------------------------------------------- | Download Route |-------------------------------------------------------------------------- | | Download route will be added to your app URL for using download links. | E.g. if your app URL is "example.com", then if your set the download route to | "download" it will be "example.com/download/{link}". | */ 'download_route' => 'download',];
You can explicitly set the filename to save and download using the given name:
$link = DownloadLink::disk('public')->filePath('uploads/test.txt')->fileName('new-text.txt')->generate();
You can also add an expiration time so that it is only available until the link expires:
$link = DownloadLink::disk('public')->filePath('uploads/test.txt')->expire(now()->addDay())->generate();
You can also Specify whether only authenticated users or guests can use the link:
// 仅通过身份验证的用户 $link = DownloadLink::disk('public')->filePath('uploads/test.txt')->auth()->generate(); // 仅游客 $link = DownloadLink::disk('public')->filePath('uploads/test.txt')->guest()->generate();
You can blacklist one or more IP addresses (the download link will not work with these IP addresses):
$link = DownloadLink::disk('public')->filePath('uploads/test.txt')->limitIp('127.0.0.1')->generate(); $link = DownloadLink::disk('public')->filePath('uploads/test.txt')->limitIp(['127.0.0.1', '127.0.0.2', '127.0.0.3'])->generate();
Alternatively, you can whitelist one or more IP addresses (download links will only apply to these IP addresses):
$link = DownloadLink::disk('public')->filePath('uploads/test.txt')->allowIp('127.0.0.1')->generate(); $link = DownloadLink::disk('public')->filePath('uploads/test.txt')->allowIp(['127.0.0.1', '127.0.0.2', '127.0.0.3'])->generate();
The default download route in the configuration file is "download", so if If your domain name is "example.com", you should use this link:
example.com/download/{link} // 例如 example.com/download/zkTu70fieUFZLGMoEP95l1RQfFj5zCOqHlM0XBTnc6ZaZTtm4GY5xPXGGLzLEAVe
Note: You need to replace {link}
with the generated link.
You can delete a link like this:
DownloadLink::delete('link'); // For example DownloadLink::delete('zkTu70fieUFZLGMoEP95l1RQfFj5zCOqHlM0XBTnc6ZaZTtm4GY5xPXGGLzLEAVe');
You can use the following command to delete expired links in the database:
php artisan download-links:remove-expired
Original address: https://github .com/armancodes/laravel-download-link
Translation address: https://learnku.com/laravel/t/49522
The above is the detailed content of [Extended recommendation] laravel-download-link (generate download link). For more information, please follow other related articles on the PHP Chinese website!