Wallogit.com
2017 © Pedro Peláez
Manager Your Project File And Media
This Package Created, For Manage Media and file in your Project, (*1)
Working with this package is very simple so let's start learning, (*2)
Require the package in your composer.json and update your dependency with composer update:, (*3)
"require": {
...
"laravel-media-manager/manager": "dev-master",
...
},
Add the package to your application service providers in config/app.php., (*4)
'providers' => [ 'Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', ... 'MediaManager\Manager\ManagerServiceProvider::class', ],
then add this line to aliases array in the config/app.php file :, (*5)
'MediaManager' => MediaManager\Manager\Facade\Manager::class,
first of all, at this package, assumed public > upload directory is Root directory for destination place for files uploaded and You should not mention it in the address
for example: public/upload/product/7/image/picture.jpg, (*6)
just you write :, (*7)
MediaManager::store($request->file('file'), 'product/7/image', 'picture.jpg');
But you can change this logic By change into config.php file with this command :, (*8)
php artisan vendor:publish
for use this package must be imported it, so write this command after namespace, (*9)
import Facade :
use MediaManager;, (*10)
you can manage saving file with store method :, (*11)
when get file with $request->file('file'), use this :, (*12)
MediaManager::store(UploadedFile $file, String $destinationPath, String $name);, (*13)
for example, we want save file into upload/product/7/image,, (*14)
MediaManager::store($request->file('file'), 'product/7/image', 'picture.jpg');
Maybe you want to make changes to the file name, to do this, use the closure instead of the third argument, (*15)
$baseName = $request->file('file')->getClientOriginalName();
list($fileName, $destinationPath) = MediaManager::store($request->file('file'), 'product/7/image', function() use ($baseName){
return 'company_name_'.time().'_'.$baseName;
});
The file is stored in the destination path and these values are returned:, (*16)
{
"company_name_1504896197_picture.png",
"yourSite.com\upload\product\7\image\"
}
Notice: all paths under are equal :
* product/7/image
* /product/7/image/
* /product/7/image
* product/7/image/, (*17)
for delete file, name and file path is enough:, (*18)
MediaManager::delete('picture.jpg', 'product/7/image');
or given array, (*19)
MediaManager::delete(['picture1.jpg', 'picture2.jpg'], 'product/7/image');
for rename file, give to rename method 3 parameters :, (*20)
first parameter : oldName or Now Name, (*21)
second parameter : new Name, (*22)
third parameter: path file, (*23)
for example:, (*24)
MediaManager::rename('oldName.jpg', 'newName', 'product/7/image');
Warning: If the destination file already exists, it will be overwritten., (*25)
for copy file, give to copy method 3 parameters :, (*26)
first parameter : file name, (*27)
second parameter : now path, (*28)
third parameter : new path, (*29)
for example:, (*30)
MediaManager::copy('picture.jpg', 'product/7/image', 'product/49/image');
for cut file,such as copy, give 3 parameters to cut method :, (*31)
first parameter : file name, (*32)
second parameter : now path, (*33)
third parameter : new path, (*34)
for example:, (*35)
MediaManager::cut('picture.jpg', 'product/7/image', 'product/49/image');
In the SmartStore method, the file type is examined using the mimetype and based on its type, the folder is created and you do not need to consider a folder for a particular type in the declaration. for example if file is one of these mime type: 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/bmp', 'image/vnd.microsoft.icon', 'image/tiff', 'image/tiff', 'image/svg+xml', 'image/svg+xml', (*36)
In fact, a folder called the image is created and used for storing, and you give this path to method product/7 instead product/7/image, (*37)
MediaManager::store(UploadedFile $file, String $destinationPath, String $name);, (*38)
for example, we want save file into upload/product/7/image,, (*39)
MediaManager::SmartStore($request->file('file'), 'product/7', 'picture.jpg');
Maybe you want to make changes to the file name, to do this, use the closure instead of the third argument, (*40)
$baseName = $request->file('file')->getClientOriginalName();
list($fileName, $destinationPath) = MediaManager::store($request->file('file'), 'product/7', function() use ($baseName){
return 'company_name_'.time().'_'.$baseName;
});
The file is stored in the destination path and these values are returned:, (*41)
{
"company_name_1504896197_picture.png",
"yourSite.com\public\upload\product\7\image\"
}
In the copy and cut method, the destination path must exist, and if it does not, you will get a mistake. In the smart way, if the destination does not exist, it initially creates it and then continues., (*42)
Warning: If the destination file already exists, it will be overwritten., (*43)
parameters are such as normal copy :, (*44)
MediaManager::SmartCopy('picture.jpg', 'product/7/image', 'product/49/image');
parameters are such as normal cut :, (*45)
MediaManager::SmartCut('picture.jpg', 'product/7/image', 'product/49/image');
# laravel-media-manager