erlandmuchasaj/laravel-file-uploader
Composer 安装命令:
composer require erlandmuchasaj/laravel-file-uploader
包简介
A simple package to help you easily upload files to your laravel project.
README 文档
README
Laravel File Uploader offers an easy way to upload files to different disks. The main purpose of the package is to remove the repeated and cumbersome code and simplify it into some simple methods.
Installation
You can install the package via composer:
composer require erlandmuchasaj/laravel-file-uploader
Usage
This package has an very easy and straight-forward usage. Just import the package and pass the file as parameter, and it will handle the rest.
use ErlandMuchasaj\LaravelFileUploader\FileUploader; Route::post('/files', function (\Illuminate\Http\Request $request) { $max_size = (int) ini_get('upload_max_filesize') * 1000; // FileUploader::images() get all image extensions ex: jpg, png, jpeg, gif, etc. // FileUploader::documents() get all documents extensions ex: 'csv', 'html', 'pdf', 'doc', 'docx', 'ppt' etc. $extensions = implode(',', FileUploader::images()); $request->validate([ 'file' => [ 'required', 'file', 'image', 'mimes:' . $extensions, 'max:'.$max_size, ] ]); $file = $request->file('file'); $response = FileUploader::store($file); // $response = FileUploader::store($file, $options); // available options (as key=>value pare) are: // `disk`, 'user_id`, `path`, `visibility` // do something with the $response // you can save it into your model etc. return redirect() ->back() ->with('success', __('File has been uploaded.')) ->with('file', $response); })->name('files.store'); /** * $response = [ * "type" => "image" * "extension" => "png" * "_extension" => "png" * "name" => "blog3" * "original_name" => "blog3.png" * "size" => 549247 * "mime_type" => "image/png" * "dimensions" => "670x841" * "path" => "uploads/1/image/blog3_1678118034.png" // <== * "url" => "/storage/uploads/1/image/blog3_1678118034.png" * "user_id" => 1 * "disk" => "local" * "visibility" => "public" * "uuid" => "dd5889c0-5057-49ef-a6ef-e3da961a47d1" * ] */
If you need to modify the config files, you should publish the migration and the config/permission.php config file with:
php artisan vendor:publish --provider="ErlandMuchasaj\LaravelFileUploader\FileUploaderServiceProvider"
Some other helper methods:
$path = 'uploads/1/image/blog3_1678118034.png'; // the path of the image where is stored. $response = FileUploader::get($path); // get file as StreamedResponse $response = FileUploader::getFile($path); // get file as content. $response = FileUploader::url($path); // full path url - /storage/uploads/1/image/blog3_1678118034.png $response = FileUploader::path($path); // C:\wamp\www\laravel-app\storage\app\uploads/1/image/blog3_1678118034.png $response = FileUploader::meta($path); // metadata about the file. /** * [ * "path" => "C:\wamp\www\laravel-app\storage\app\uploads/1/image/blog3_1678118034.png" * "url" => "/storage/uploads/1/image/blog3_1678118034.png" * "visibility" => "public" * "mimeType" => "image/png" * "size" => "536.37 KB" * "last_modified" => "1 hour ago" * "name" => "blog3_1678118034.png" * "pathinfo" => [ * "dirname" => "uploads/1/image" * "basename" => "blog3_1678118034.png" * "extension" => "png" * "filename" => "blog3_1678118034" * ] * ] */ $response = FileUploader::download($path, 'something_nice'); // download the file as StreamedResponse $response = FileUploader::getVisibility($path); // file visibility when applicable private/public $response = FileUploader::setVisibility($path, 'private'); // change file visibility $response = FileUploader::remove($path); // delete a file
Also, some other size converting helper functions are available for example:
$size = 549247; FileUploader::formatBytes($size); // "536.37 KB" FileUploader::convertBytesToSpecified($size, 'KB'); // 536.37KB FileUploader::convertBytesToSpecified($size, 'MB'); // 0.52MB
Support me
I invest a lot of time and resources into creating best in class open source packages.
If you found this package helpful you can show support by clicking on the following button below and donating some amount to help me work on these projects frequently.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please see SECURITY for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
erlandmuchasaj/laravel-file-uploader 适用场景与选型建议
erlandmuchasaj/laravel-file-uploader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.18k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2023 年 03 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「media」 「file」 「library」 「cms」 「upload」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 erlandmuchasaj/laravel-file-uploader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 erlandmuchasaj/laravel-file-uploader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 erlandmuchasaj/laravel-file-uploader 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
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
PMVC Plugin for File information
Mapper for accessing resources in KWCMS
统计信息
- 总下载量: 9.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-07