alhadi/laravel_file_manager
Composer 安装命令:
composer require alhadi/laravel_file_manager
包简介
Official ArtinCMS.com Laravel File Manager Package
关键字:
README 文档
README
laravel file manager is a package for
- manage file uploaded by users with check ACL. you can upload file with custom size
- generate download link
- store file in Sotrage folder
- optimize image
- crop image when file upload , edit file or generate link with three kind of crop .
Requiments
- PHP >= 7.0
- Laravel 5.5|5.6
The package will use these optimizers if you wnat to enable optimization:
Installation
Quick installation
composer require "alhadi/laravel_file_manager"
for laravel less than 5.5
Register provider and facade on your config/app.php file.
'providers' => [..., ArtinCMS\LFM\LFMServiceProvider::class,]
'aliases' => [..., 'FileManager' => ArtinCMS\LFM\Facades\FileManager::class,]
publish vendor
$ php artisan vendor:publish --provider="ArtinCMS\LFM\LFMServiceProvider"if update package for publish vendor you should run :
$ php artisan vendor:publish --provider="ArtinCMS\LFM\LFMServiceProvider" --force
migrate tabales
$ php artisan migrate
seed data to lfm_file_mime_type table
php artisan db:seed --class="ArtinCMS\LFM\Database\Seeds\FilemanagerTableSeeder"
more installation details
The package will use these optimizers if they are present on your system:
for install this package in your server :
Here's how to install all the optimizers on Ubuntu:
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):
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
for more information you can visit image-optimizer
usage
for use this package you should use bellow helper function anywhere in your project such as in your controller . this helper function- create html modal for show manager
- create html modal button
- set your options
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 ;
- $section = section name for example 'FileManager'; $options : is options you want to impplement in this package example :
$options = ['size_file' => 100, 'max_file_number' => 30, 'true_file_extension' => ['png','jpg']]; </pre> </div>
//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) ;
}
Manager is section name . to show inserted file , this package provide 4 view . you can
call these view in callback function as show in above example .
inserted view is : list,grid,small,medium,large
$modal_id : this option use to assign id to main modal and default is 'FileManager' .
$header : this option use to set modal header .and default is 'File manager' .
</li>
you can access to file manager with :http://www.yourdomain.com/LFM/ShowCategories
Helper Functions
in this section we descripe some most helpfull function . you can use this functions in your project .Save File
for save file in your project you can use LFM_SaveMultiFile and LFM_SaveSingleFile . in continue we explain two functions .Save Multi File
this helpers use for save multi inserted files in fileable table :$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 .
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.
Save single File
if you want save file in one to many relation and save file_id in your table models you should use this helpers .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).
Direct upload
if you want upload file in specific path you can use this helpers .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 .
$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'];
load files
Load Multi Files
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 .
Load Single Files
for load single file you can use this helpers as below :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 .
Show Files
Show Multi File
for show inserted files you can use this helpers function .The diffrent between this function and LFM_LoadMultiFile is , you cant delete files .LFM_ShowMultiFile($obj_model, $type, $relation_name )
Show Single Files
for show single files you can this helpers function . remember you cant delete file .LFM_ShowingleFile($obj_model, $column_name, $column_option_name)
Generate Link
Generate Download Link
whit this below helper function you can generate download link in anywhere of your project .LFM_GenerateDownloadLink($type, $id , $size_type, $default_img, $quality , $width, $height)
- if you want generate file link with ID the $type = 'ID' and if you want generate by name you can use $type = 'Name'
- $id : if you want generate link with id you should fill this item with file id and default is -1 that reffer no file id selected .
- $size_type can pick one on of : original , large , medium , small that reffer which size you want to download
- if image not found with $default_img you can choose image you want to show , default is '404.png'
- $quality is quality of image , it is between 0 and 100 .
- $width is width of result image
- $height is height of result image
Generate Base64 Image
whit this below helper function you can create Base64 Image .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 .
Genrate public link
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 functionLFM_GeneratePublicDownloadLink($path,$filename) </pre> </div> 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 .
Custom config
if you want to have custom config you can chage config/laravel_file_manager.php file as you want .
- 'private_middlewares' and 'public_middlewares' describe what middelware should assign to private and public route ,you can add auth and other middelware you want .
- with 'private_route_prefix' and 'public_route_prefix' you can change prefix of private and public route .
- 'allowed' reffer wich mime type files can upload
- 'allowed_pic' is reffer wich mime type is recognize as picture
- with 'size_large' ,'size_large' , 'size_large' and 'size_large' when upload file you can define size of upload deppend of type .
- 'driver_disk' is deriver you use in your project
- 'user_model' is path of your user model .
- 'Optimise_image' if is true and do serve config as tell in installation section . all picture optimize before save in your storage .
- with 'crop_chose' you can choose wich crop type use when upload file (when create large ,medium and small size of picture). you can set it one of : fit,resize and smart that 'fit' is default crop and resize resize image with due attention to config size you set and smart type is smart crop but it was slowler than other crop type .
Example
THe full Example :
Example of use LFM_SaveMultiFile and LFM_SaveSingleFile
in this example we assing zip file and user profile picture to article and save it . at first in Route :
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 :
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 :
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')); } </pre> <pre> 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')); } </pre> <pre> 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')); } </pre> <pre> 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 ; } </pre> <pre> 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 ; } </pre> </div>and in multisection.blade.php
{!! $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
{!! $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') ; }
alhadi/laravel_file_manager 适用场景与选型建议
alhadi/laravel_file_manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「storage」 「laravel」 「Media Manager」 「artincms」 「مد�」 「ر�」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alhadi/laravel_file_manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alhadi/laravel_file_manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alhadi/laravel_file_manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
Laravel Media Popup to upload/view the files
Asset Manager Laravel package for Gigcodes UI Library
The YADM migrations
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-26