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

Overview

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:

'download', ]; ">
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 [email protected] instead of using the issue tracker.

Credits

License

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

You might also like...
Laravel magical helpers such as Controllers / Requests / Models

Laravel Magic provides Abstract Controller, Model, generic Request, Traits, Exceptions and various middlewares in order to generate very easily and quickly API resources from scratch.

Slim Jam is a demo application to provide examples for composer package, PHPSpreadsheet, Shopify API etc. usages.

SLIM JAM Slim Jam is a demo application to provide examples for composer package, PHPSpreadsheet, Shopify API etc. usages. This project aims to take a

This package allows you to render livewire components like a blade component, giving it attributes, slots etc

X-livewire This package allows you to render livewire components like a blade component, giving it attributes, slots etc. Assuming you wanted to creat

Library for generating random names (for table-top roleplaying games)

RPG-Name-Generator The RPG character name generator library is designed to create list of random names used for table-top role-playing games. This lib

Admin Order Product Links
Admin Order Product Links

JBrada/AdminOrderProductLinks A simple module adds a navigation link between order, shipment, invoice and credit memo items and its related products.

A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr.
A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr.

PHP Paginator A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr. The "first" and "last" page l

A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.
A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache.

Laravel OTP Introduction A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache. The ca

Locust are malware that can delete all folders, files, etc. on the system; I
Locust are malware that can delete all folders, files, etc. on the system; I

Locust are malware that can delete all folders, files, etc. on the system; It was originally designed for web systems.

Releases(v1.1.0)
Owner
Arman Ahmadi
Backend Developer
Arman Ahmadi
A simple laravel package to validate console commands arguments and options.

Command Validator A simple laravel package to validate console commands arguments and options. Installation Require/Install the package using composer

Touhidur Rahman 20 Jan 20, 2022
Laravel SEO - This is a simple and extensible package for improving SEO via meta tags, such as OpenGraph tags.

This is a simple and extensible package for improving SEO via meta tags, such as OpenGraph tags.

ARCHTECH 191 Dec 30, 2022
Avatar Generating Package for Laravel.

Avatar Generating Package for Laravel.

Tall 1 Oct 28, 2021
Gallium is a TALL stack starter kit offering a robust set of options enabling you to get up and running in a snap.

Very short description of the package This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention o

null 1 Nov 20, 2021
Let users pick a color from a fixed list of options.

Let users pick a color from a fixed list of options. This packages implements a new ColorPalette field as described in the mini-series on my blog. It

Ryan Chandler 2 Oct 7, 2022
Make your church sermons available for download. For the latest version, go:

Laravel Church Sermons App Laravel church sermons app is basically an app for churches to make available the messages preached in church for all membe

Dammy 28 Nov 13, 2022
Otpify is a Laravel package that provides a simple and elegant way to generate and validate one time passwords.

Laravel Otpify ?? Introduction Otpify is a Laravel package that provides a simple and elegant way to generate and validate one time passwords. Install

Prasanth Jayakumar 2 Sep 2, 2022
Laravel breeze is a PHP Laravel library that provides Authentication features such as Login page , Register, Reset Password and creating all Sessions Required.

About Laravel breeze To give you a head start building your new Laravel application, we are happy to offer authentication and application starter kits

null 3 Jul 30, 2022
Links statistics & link tracking for laravel 5, It tracks down browsers, operating systems, languages and more

Links Links statistics for laravel 5 Table Of Contents Installation Configuration Usage Installation To install charts use composer Download composer

Erik C. Forés 52 Jul 31, 2021
A simple Content Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc.

Laravel Moderation A simple Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc. Keep yo

Alex Kyriakidis 509 Dec 30, 2022