Home > PHP Framework > Laravel > [Extended recommendation] laravel-download-link (generate download link)

[Extended recommendation] laravel-download-link (generate download link)

藏色散人
Release: 2020-11-02 13:56:20
forward
3454 people have browsed it

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!

[Extended recommendation] laravel-download-link (generate download link)

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
Copy after login

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
Copy after login

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"
Copy after login

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',];
Copy after login

Use

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();
Copy after login

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();
Copy after login

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();
Copy after login

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();
Copy after login

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();
Copy after login

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
Copy after login

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');
Copy after login

You can use the following command to delete expired links in the database:

php artisan download-links:remove-expired
Copy after login

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template