├── .styleci.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── config.php ├── routes └── laravel-secret-image.php └── src ├── Http └── Controllers │ └── LaravelSecretImageController.php ├── LaravelSecretImage.php ├── LaravelSecretImageFacade.php └── LaravelSecretImageServiceProvider.php /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | disabled: 4 | - single_class_element_per_statement 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | Welcome To ChangeLog. 4 | 5 | ## 1.2.0 - 2020-09-03 6 | 7 | - Stable Version 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Mohsen Bostan 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 all 13 | 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 THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Secret Image 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/mohsenbostan/laravel-secret-image.svg?style=flat-square)](https://packagist.org/packages/mohsenbostan/laravel-secret-image) 4 | [![Total Downloads](https://img.shields.io/packagist/dt/mohsenbostan/laravel-secret-image.svg?style=flat-square)](https://packagist.org/packages/mohsenbostan/laravel-secret-image) 5 | [![Build Status](https://travis-ci.com/mohsenbostan/laravel-secret-image.svg?branch=master)](https://travis-ci.com/mohsenbostan/laravel-secret-image) 6 | 7 | This package helps you to save your images secretly and show them just to authenticated users. 8 | 9 | ## Installation 10 | 11 | You can install the package via composer: 12 | 13 | ```bash 14 | composer require mohsenbostan/laravel-secret-image 15 | ``` 16 | after installing package using composer, you should publish configs: 17 | 18 | ``` bash 19 | php artisan vendor:publish --provider=Mohsenbostan\LaravelSecretImage\LaravelSecretImageServiceProvider 20 | ``` 21 | 22 | ## Usage 23 | 24 | **Custom Storage Driver** 25 | 26 | you can set a custom storage driver in `config/laravel-secret-image.php` 27 | 28 | ```php 29 | env('FILESYSTEM_DRIVER', 'local'), 38 | ]; 39 | ``` 40 | 41 | **Custom Middlewares** 42 | 43 | you can set custom middlewares to protect images in `config/laravel-secret-image.php` 44 | 45 | ```php 46 | [ 53 | 'auth' 54 | ] 55 | ]; 56 | ``` 57 | 58 | **Save Single Secret Image** 59 | 60 | `saveSingleImage` method will save image and return the image path. 61 | 62 | ``` php 63 | use \Mohsenbostan\LaravelSecretImage\LaravelSecretImage; 64 | 65 | $image = LaravelSecretImage::saveSingleImage(request()->file('image')); 66 | ``` 67 | 68 | **Save Multiple Secret Images** 69 | 70 | `saveMultiImages` method will save all images and return the images' path. 71 | 72 | ``` php 73 | use \Mohsenbostan\LaravelSecretImage\LaravelSecretImage; 74 | 75 | $images = LaravelSecretImage::saveMultiImages(request()->file('images')); 76 | ``` 77 | 78 | **Get Secret Image Url** 79 | 80 | `getImageUrl` method will return image url. 81 | 82 | ``` php 83 | use \Mohsenbostan\LaravelSecretImage\LaravelSecretImage; 84 | 85 | $url = LaravelSecretImage::getImageUrl($image); 86 | ``` 87 | 88 | ### Testing 89 | 90 | ``` bash 91 | composer test 92 | ``` 93 | 94 | ### Changelog 95 | 96 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 97 | 98 | ## Contributing 99 | 100 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 101 | 102 | ### Security 103 | 104 | If you discover any security related issues, please email mohsenbostandev@gmail.com instead of using the issue tracker. 105 | 106 | ## Credits 107 | 108 | - [Mohsen Bostan](https://github.com/mohsenbostan) 109 | - [All Contributors](../../contributors) 110 | 111 | ## License 112 | 113 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 114 | 115 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mohsenbostan/laravel-secret-image", 3 | "description": "A package to save images secretly.", 4 | "keywords": [ 5 | "mohsenbostan", 6 | "laravel-secret-image" 7 | ], 8 | "homepage": "https://github.com/mohsenbostan/laravel-secret-image", 9 | "license": "MIT", 10 | "type": "library", 11 | "authors": [ 12 | { 13 | "name": "Mohsen Bostan", 14 | "email": "mohsenbostandev@gmail.com", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": "^7.3", 20 | "illuminate/support": "^6.0 || ^7.0 || ^8.0", 21 | "intervention/image": "^2.5" 22 | }, 23 | "require-dev": { 24 | "orchestra/testbench": "^4.0", 25 | "phpunit/phpunit": "^8.0" 26 | }, 27 | "autoload": { 28 | "psr-4": { 29 | "Mohsenbostan\\LaravelSecretImage\\": "src" 30 | } 31 | }, 32 | "autoload-dev": { 33 | "psr-4": { 34 | "Mohsenbostan\\LaravelSecretImage\\Tests\\": "tests" 35 | } 36 | }, 37 | "scripts": { 38 | "test": "vendor/bin/phpunit", 39 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 40 | 41 | }, 42 | "config": { 43 | "sort-packages": true 44 | }, 45 | "extra": { 46 | "laravel": { 47 | "providers": [ 48 | "Mohsenbostan\\LaravelSecretImage\\LaravelSecretImageServiceProvider" 49 | ], 50 | "aliases": { 51 | "LaravelSecretImage": "Mohsenbostan\\LaravelSecretImage\\LaravelSecretImageFacade" 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DRIVER', 'local'), 10 | 11 | /* 12 | * Default Middlewares To Protect Images 13 | */ 14 | 'middlewares' => [ 15 | 'auth' 16 | ] 17 | ]; 18 | -------------------------------------------------------------------------------- /routes/laravel-secret-image.php: -------------------------------------------------------------------------------- 1 | name('secret-image.')->group(function () { 7 | Route::get('/secret-image', [ 8 | LaravelSecretImageController::class, 9 | 'showImage' 10 | ])->name('show-image'); 11 | }); 12 | -------------------------------------------------------------------------------- /src/Http/Controllers/LaravelSecretImageController.php: -------------------------------------------------------------------------------- 1 | exists(request('image'))) { 22 | $image = Storage::disk($storage_driver)->get(request('image')); 23 | return Image::make($image)->response(); 24 | } 25 | 26 | throw new HttpException(422, 'image not found.'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/LaravelSecretImage.php: -------------------------------------------------------------------------------- 1 | putFile($path, $image) 27 | : Storage::disk($storage_driver)->putFileAs($path, $image, $newImageName . '.' . $image->getClientOriginalExtension()); 28 | } 29 | 30 | throw new HttpException(422, 'the provided path is not secret. Please remove the `public` from the beginning.'); 31 | } 32 | 33 | /** 34 | * Save Multiple Images 35 | * @param $images 36 | * @param string $path 37 | * @return array 38 | */ 39 | public static function saveMultiImages($images, $path = 'secret-image'): array 40 | { 41 | if (Str::substr($path, 0, 6) !== 'public') { 42 | 43 | $storage_driver = config('laravel-secret-image.storage_driver'); 44 | $key = 0; 45 | $images_path = []; 46 | foreach ($images as $image) { 47 | $images_path[$key++] = Storage::disk($storage_driver)->putFile($path, $image); 48 | } 49 | return $images_path; 50 | } 51 | 52 | throw new HttpException(422, 'the provided path is not secret. Please remove the `public` from the beginning.'); 53 | } 54 | 55 | /** 56 | * Get Image Url 57 | * @param $image 58 | * @return string 59 | */ 60 | public static function getImageUrl($image): string 61 | { 62 | return route('secret-image.show-image') . "?image=$image"; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/LaravelSecretImageFacade.php: -------------------------------------------------------------------------------- 1 | loadRoutesFrom( __DIR__.'/../routes/laravel-secret-image.php'); 15 | 16 | if ($this->app->runningInConsole()) { 17 | $this->publishes([ 18 | __DIR__.'/../config/config.php' => config_path('laravel-secret-image.php'), 19 | ], 'config'); 20 | } 21 | } 22 | 23 | /** 24 | * Register the application services. 25 | */ 26 | public function register() 27 | { 28 | // Automatically apply the package configuration 29 | $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-secret-image'); 30 | 31 | // Register the main class to use with the facade 32 | $this->app->singleton('laravel-secret-image', function () { 33 | return new LaravelSecretImage; 34 | }); 35 | } 36 | } 37 | --------------------------------------------------------------------------------