├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── psalm.xml.dist └── src ├── Exceptions └── CantOpenFileFromUrlException.php └── UrlUploadedFile.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-url-uploaded-file` will be documented in this file 4 | 5 | ## 1.0.0 - 2020-10-25 6 | 7 | - Initial release 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Daniel Naxon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Uploade files from URLs in Laravel 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/naxon/laravel-url-uploaded-file.svg?style=flat-square)](https://packagist.org/packages/naxon/laravel-url-uploaded-file) 4 | ![Tests](https://github.com/naxon/laravel-url-uploaded-file/workflows/Tests/badge.svg?branch=main) 5 | [![Total Downloads](https://img.shields.io/packagist/dt/naxon/laravel-url-uploaded-file.svg?style=flat-square)](https://packagist.org/packages/naxon/laravel-url-uploaded-file) 6 | 7 | This package extends Laravel's [`UploadedFile`](https://github.com/laravel/framework/blob/8.x/src/Illuminate/Http/UploadedFile.php) functionality using file URLs instead of regular file uploads. 8 | 9 | Read the full post in my blog: https://naxon.dev/blog/upload-files-from-urls-in-laravel 10 | 11 | ## Installation 12 | 13 | You can install the package via composer: 14 | 15 | ```bash 16 | composer require naxon/laravel-url-uploaded-file 17 | ``` 18 | 19 | ## Usage 20 | 21 | ``` php 22 | use Naxon\UrlUploadedFile\UrlUploadedFile; 23 | 24 | $file = UrlUploadedFile::createFromUrl('https://naxon.dev/assets/img/portrait.jpg'); 25 | ``` 26 | 27 | Now, because `UrlUploadedFile` extends `UploadedFile`, you can [store](https://laravel.com/docs/8.x/requests#storing-uploaded-files) it, get its [path and extension](https://laravel.com/docs/8.x/requests#storing-uploaded-files) and use `UploadedFile`'s functionality with it. 28 | 29 | ## Testing 30 | 31 | ``` bash 32 | composer test 33 | ``` 34 | 35 | ## Changelog 36 | 37 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 38 | 39 | ## Roadmap 40 | 41 | Version 1.0 provides basic functionality only. It was extracted from a real project I was working on. The plan for version 2.0 is to extend the functionality by adding more downloaders. 42 | 43 | ## Contributing 44 | 45 | Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. 46 | 47 | ## Security Vulnerabilities 48 | 49 | Please review [our security policy](../../security/policy) on how to report security vulnerabilities. 50 | 51 | ## Credits 52 | 53 | - [Daniel Naxon](https://github.com/NaxonD) 54 | - [Spatie](https://github.com/spatie) - On the idea of how to [download files](https://github.com/spatie/laravel-medialibrary/blob/9dc99067cb78f6902b2f70601fb62fe16ba0f7ec/src/Downloaders/DefaultDownloader.php). 55 | - [All Contributors](../../contributors) 56 | 57 | ## License 58 | 59 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 60 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "naxon/laravel-url-uploaded-file", 3 | "description": "A package to leverage Laravel's UploadedFile functionality from URLs.", 4 | "keywords": [ 5 | "naxon", 6 | "laravel", 7 | "laravel-url-uploaded-file" 8 | ], 9 | "type": "library", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Daniel Naxon", 14 | "email": "naxond@gmail.com", 15 | "homepage": "https://naxon.dev" 16 | } 17 | ], 18 | "require": { 19 | "php": "^7.4", 20 | "illuminate/http": "^8.0" 21 | }, 22 | "require-dev": { 23 | "friendsofphp/php-cs-fixer": "^2.16", 24 | "orchestra/testbench": "^6.2", 25 | "phpunit/phpunit": "^9.4", 26 | "vimeo/psalm": "^4.0" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "Naxon\\UrlUploadedFile\\": "src" 31 | } 32 | }, 33 | "autoload-dev": { 34 | "psr-4": { 35 | "Naxon\\UrlUploadedFile\\Tests\\": "tests" 36 | } 37 | }, 38 | "scripts": { 39 | "psalm": "vendor/bin/psalm", 40 | "test": "vendor/bin/phpunit --colors=always", 41 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage", 42 | "format": "vendor/bin/php-cs-fixer" 43 | }, 44 | "config": { 45 | "sort-packages": true 46 | }, 47 | "minimum-stability": "dev", 48 | "prefer-stable": true 49 | } 50 | -------------------------------------------------------------------------------- /psalm.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Exceptions/CantOpenFileFromUrlException.php: -------------------------------------------------------------------------------- 1 |