dev-master
9999999-devOfficial ArtinCMS.com Laravel File Manager Package
MIT
The Requires
by adel.raheli
laravel storage media manager artincms مدیریت فایل مدیا منیجر artincms.com آرتین سی ام اس
Official ArtinCMS.com Laravel File Manager Package
laravel file manager is a package for, (*1)
composer require "artincms/laravel_file_manager"
Register provider and facade on your config/app.php file., (*2)
'providers' => [
...,
ArtinCMS\LFM\LFMServiceProvider::class,
]
'aliases' => [
...,
'FileManager' => ArtinCMS\LFM\Facades\FileManager::class,
]
$ php artisan vendor:publish --provider="ArtinCMS\LFM\LFMServiceProvider"
if update package for publish vendor you should run :, (*3)
$ php artisan vendor:publish --provider="ArtinCMS\LFM\LFMServiceProvider" --force
$ php artisan migrate
php artisan db:seed --class="ArtinCMS\LFM\Database\Seeds\FilemanagerTableSeeder"
The package will use these optimizers if they are present on your system:, (*4)
for install this package in your server : , (*5)
Here's how to install all the optimizers on Ubuntu:, (*6)
sudo apt-get install jpegoptim
sudo apt-get install optipng
sudo apt-get install pngquant
sudo npm install -g svgo
sudo apt-get install gifsicle
And here's how to install the binaries on MacOS (using Homebrew):, (*7)
brew install jpegoptim
brew install optipng
brew install pngquant
brew install svgo
brew install gifsicle
for enable optimizer in package you shoul go config/laravel_file_manager.php and set 'Optimise_image'= true, (*8)
<, (*9)
p>for more information you can visit image-optimizer, (*10)
for use this package you should use bellow helper function anywhere in your project such as in your controller . this helper function, (*11)
LFM_CreateModalFileManager($section, $options , $insert , $callback , $modal_id , $header , $button_id, $button_content)
that $section is Require and other input is optional .for use output of filemanager you should install jquery 3 and bootstrap 4 ;, (*12)
$options = ['size_file' => 100, 'max_file_number' => 30, 'true_file_extension' => ['png','jpg']];
//the inserted file result is
{
Manager :
available:1,
data :
[{
0 :
{
file :
{
height : "0"
icon : "image"
id : 115
name : "photo2017-04-1512-45-2"
quality : "100"
size : 60187
type : "original"
user : "faramarz"
version : null
width: "0"
},
full_url: "http://127.0.0.1:8000/LFM/DownloadFile/ID/115/original/404.png/100/0/0",
message: "File with ID :115 Inserted",
success:true
url: "/LFM/DownloadFile/ID/115/original/404.png/100/0/0",
full_url_large:"http://127.0.0.1:8000/LFM/DownloadFile/ID/24/small/404.png/100/300/180",
full_url_medium:"http://127.0.0.1:8000/LFM/DownloadFile/ID/24/medium/404.png/100/300/180",
}
}],
view :
{
'list' : 'html grid view code' ,
'grid' : 'html grid view code' ,
'small' :'html small view code' ,
'medium' : 'html thumb view code' ,
'large' : 'html large view code'
}
}
//to show above data to small view you can use this function
function callback(result)
{
$('#show_area_small').html(result.Manager.view.small) ;
}
you can access to file manager with :http://www.yourdomain.com/LFM/ShowCategories, (*13)
in this section we descripe some most helpfull function . you can use this functions in your project ., (*14)
for save file in your project you can use LFM_SaveMultiFile and LFM_SaveSingleFile . in continue we explain two functions ., (*15)
this helpers use for save multi inserted files in fileable table :, (*16)
$res = LFM_SaveMultiFile($obj_model, $section, $type , $relation_name , $attach_type)
at first you should define your morph relation in your model . we create files relation and and put it in trait .for use this relation should use it in your model ., (*17)
public function files()
{
return $this->morphToMany('ArtinCMS\LFM\Models\File' , 'fileable','lfm_fileables','fileable_id','file_id')->withPivot('type')->withTimestamps() ;
}
you can use this trait or create your morph relation . the $obj_model is name of your model , $section is name of your section , $type is type of file (music,picture,zip,..) its optional and default is null , $relation_name is name of morph relation and default is 'files' and with $attach_type you can select attach or sync file., (*18)
if you want save file in one to many relation and save file_id in your table models you should use this helpers ., (*19)
LFM_SaveSingleFile($obj_model, $column_name, $section,$column_option_name)
The $obj_model is name of your model ($article = new Article), and column_name is name of column you want save inserted id for example 'default_img_file_id' , $section is name of section and $column_option_name is name of column that save options(for example save width,height,quality,.. in json format)., (*20)
if you want upload file in specific path you can use this helpers ., (*21)
LFM_CreateModalUpload($section, $callback , $options, $result_area_id , $modal_id , $header , $button_id , $button_content)
the input helper functions is same LFM_CreateModalFileManager with diffrent $result_area_id that define area id when upload file . you should define your favorit path in options as below ., (*22)
$options = ['size_file' => 1000, 'max_file_number' =>5, 'min_file_number' => 2,'show_file_uploaded'=>'medium', 'true_file_extension' => ['png','jpg','zip'],'path'=>'myuploads/sdadeghi'];
for load files (for example you can use this helper functons when you want edit) you can use this helpers function
LFM_LoadMultiFile($obj_model, $section, $type = null, $relation_name = 'files')
the input this helpers funciton is same to LFM_SaveMultiFile and you can get files .Remember you should use same section name when you save file and load it .you can delete our insert new file after load files ., (*23)
for load single file you can use this helpers as below :, (*24)
LFM_loadSingleFile($obj_model, $column_name, $section, $column_option_name = false)
the input this helpers function is same to LFM_SaveSingleFile . just remember you should same section name when you save and load file .you can delete our insert new file after load files ., (*25)
for show inserted files you can use this helpers function ., (*26)
LFM_ShowMultiFile($obj_model, $type, $relation_name )
The diffrent between this function and LFM_LoadMultiFile is , you cant delete files ., (*27)
for show single files you can this helpers function . remember you cant delete file ., (*28)
LFM_ShowingleFile($obj_model, $column_name, $column_option_name)
whit this below helper function you can generate download link in anywhere of your project ., (*29)
LFM_GenerateDownloadLink($type, $id , $size_type, $default_img, $quality , $width, $height)
whit this below helper function you can create Base64 Image ., (*30)
LFM_GetBase64Image($file_id, $size_type, $not_found_img , $inline_content , $quality , $width , $height )
this helpers config as above with different $inline_content that if it was true you can create base 64 Image ., (*31)
if you create shortcut from storage/public_folder in your public folder you can access file directly . as see in below box you can create public download path with this helper function, (*32)
LFM_GeneratePublicDownloadLink($path,$filename)
that $psth is path to file and $filename is name of disc file . for example you want access the logo site picture you can upload this file in public folder and access directly with above helper function .
if you want to have custom config you can chage config/laravel_file_manager.php file as you want ., (*33)
THe full Example :, (*34)
<, (*35)
h5>Example of use LFM_SaveMultiFile and LFM_SaveSingleFile, (*36)
<, (*37)
h5>, (*38)
in this example we assing zip file and user profile picture to article and save it . at first in Route :, (*39)
Route::get('/MultiFile', 'HomeController@multiSection')->name('multiSection');
Route::get('/MultiFile/{id}', 'HomeController@multiSectionEdit')->name('multiSectionEdit');
Route::get('/ShowMultiFile/{id}', 'HomeController@showMultiFile')->name('showMultiFile');
Route::post('/StoreArticle', ['as' => 'StoreArticle', 'uses' => 'HomeController@StoreArticle']);
Route::post('/StoreEditArticle', ['as' => 'StoreEditArticle', 'uses' => 'HomeController@StoreEditArticle']);
you should define your relation in article models :, (*40)
use ArtinCMS\LFM\Traits\lfmFillable ;
use ArtinCMS\LFM\Models\File;
class Article extends Model
{
use lfmFillable;
}
as you see multisection route use for save article with zip file and profile picture . in your controller :, (*41)
public function multiSection()
{
$optionsAttach = ['size_file' => 100, 'max_file_number' => 5, 'true_file_extension' => ['zip']];
$option_single = ['size_file' => 100, 'max_file_number' => 1, 'true_file_extension' => ['png','jpg']];
$attach = LFM_CreateModalFileManager('Attach',$optionsAttach , 'insert','showAttach');
$single = LFM_CreateModalFileManager('Single',$option_single , 'insert','showSingle');
return view('multiSection',compact('attach','single'));
}
public function multiSectionEdit($id)
{
$optionsAttach = ['size_file' => 100, 'max_file_number' => 5, 'true_file_extension' => ['zip']];
$option_single = ['size_file' => 100, 'max_file_number' => 1, 'true_file_extension' => ['png','jpg']];
$attach = LFM_CreateModalFileManager('Attach',$optionsAttach , 'insert','showAttach');
$article = Article::find($id);
$load_attch = LFM_LoadMultiFile($article,'Attach','zip','files') ;
$single = LFM_CreateModalFileManager('Single',$option_single , 'insert','showSingle');
$load_single = LFM_loadSingleFile($article,'default_img_file_id','Single');
return view('multiSectionedit',compact('attach','single','load_attch','load_single','article'));
}
public function showMultiFile ($id)
{
$article = Article::find($id);
$show_attch = LFM_ShowMultiFile($article,'zip','files') ;
$show__single = LFM_ShowingleFile($article,'default_img_file_id','Single');
return view('showMultiFile',compact('show_attch','show__single','article'));
}
public function StoreArticle(Request $request)
{
$article = new Article ;
$article->title = $request->title ;
$article->body = $request->body ;
$article->save() ;
$res['Attach'] = LFM_SaveMultiFile($article,'Attach','zip','files' , 'attach');
$res['Single'] = LFM_SaveSingleFile($article,'default_img_file_id','Single','options');
return $res ;
}
public function StoreEditArticle(Request $request)
{
$article =Article::find($request->id);
$res['Attach'] = LFM_SaveMultiFile($article,'Attach','zip','files' , 'sync');
$res['Single'] = LFM_SaveSingleFile($article,'default_img_file_id','Single','options');
return $res ;
}
and in multisection.blade.php, (*42)
{!! $attach['button'] !!}
{!! $attach['modal_content'] !!}
div#show_area_Attach_list
function showAttach(res) {
$('#show_area_Attach_list').html(res.Attach.view.list) ;
$('#show_area_Attach_grod').html(res.Attach.view.grid) ;
$('#show_area_Attach_small').html(res.Attach.view.small) ;
$('#show_area_Attach_medium').html(res.Attach.view.medium) ;
$('#show_area_Attach_large').html(res.Attach.view.large) ;
}
and in multisectioneditl.blade.php, (*43)
{!! $attach['button'] !!}
{!! $attach['modal_content'] !!}
div#show_area_Attach {!! $load_attch['view']['list'] !!}
function showAttach(res) {
$('#show_area_Attach').html(res.Attach.view.list,'slider') ;
}
Official ArtinCMS.com Laravel File Manager Package
MIT
laravel storage media manager artincms مدیریت فایل مدیا منیجر artincms.com آرتین سی ام اس