Skip to content
This repository has been archived by the owner. It is now read-only.
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Generate download links in your Laravel applications

Latest Version on Packagist Scrutinizer Code Quality GitHub Tests Action Status Total Downloads

This package allows you to generate download links for files.

Once installed you can do stuff like this:

$link = DownloadLink::disk('public')->filePath('uploads/test.txt')->generate();
// zkTu70fieUFZLGMoEP95l1RQfFj5zCOqHlM0XBTnc6ZaZTtm4GY5xPXGGLzLEAVe

The default download route in the config file is "download", so if your domain is "example.com", then you should use this link:

example.com/download/{link}

// For example
example.com/download/zkTu70fieUFZLGMoEP95l1RQfFj5zCOqHlM0XBTnc6ZaZTtm4GY5xPXGGLzLEAVe

Note: You should replace {link} with the generated link.

Installation

You can install the package via composer:

composer require armancodes/laravel-download-link

You can publish and run the migrations with:

php artisan vendor:publish --provider="Armancodes\DownloadLink\DownloadLinkServiceProvider" --tag="migrations"

php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="Armancodes\DownloadLink\DownloadLinkServiceProvider" --tag="config"

This is the contents of the published config 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',
];

Usage

You can explicitly set the file name to be saved and downloaded with the given name:

$link = DownloadLink::disk('public')->filePath('uploads/test.txt')->fileName('new-text.txt')->generate();

Expire time can also be added, so that the link will only be available before it expires:

$link = DownloadLink::disk('public')->filePath('uploads/test.txt')->expire(now()->addDay())->generate();

You can also specify if only authenticated users or guests should be able to use the link:

// Authenticated users only
$link = DownloadLink::disk('public')->filePath('uploads/test.txt')->auth()->generate();

// Guests only
$link = DownloadLink::disk('public')->filePath('uploads/test.txt')->guest()->generate();

You may put one or more ip addresses into a blacklist (Download links won't work with those 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();

Or you may put one or more ip addresses into whitelist (Download links will ONLY work with those 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 config file is "download", so if your domain is "example.com", then you should use this link to download:

example.com/download/{link}

// For example
example.com/download/zkTu70fieUFZLGMoEP95l1RQfFj5zCOqHlM0XBTnc6ZaZTtm4GY5xPXGGLzLEAVe

Note: You should replace {link} with the generated link.

You can delete a link like this:

DownloadLink::delete('link');

// For example
DownloadLink::delete('zkTu70fieUFZLGMoEP95l1RQfFj5zCOqHlM0XBTnc6ZaZTtm4GY5xPXGGLzLEAVe');

You may delete the expired links in the database using the command below:

php artisan download-links:remove-expired

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email me@armancodes.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

A simple Laravel package for generating download links with options such as expire time, IP restrictions, etc.

Resources

License

Packages

No packages published

Languages