alighale / laravel-file-manager
此包已废弃,不再维护。未建议替代包。
此包最新版本(1.2.1)没有可用的许可证信息。
上传文件并下载:(笑脸)
1.2.1
2020-03-05 10:02 UTC
Requires
- php: ^7.2
- intervention/image: ^2.5
- laravel/framework: ^6.2
README
安装
composer require alighale/laravel-file-manger
您必须将服务提供者添加到 config/app.php
'providers' => [ // for laravel 5.8 and below \AliGhale\FileManager\FileManagerServiceProvider::class, ];
发布您的配置文件和迁移
php artisan vendor:publish
配置
config/filemanager.php
return [ "type" => "default", "types" => [ "default" => [ "provider" => \AliGhale\FileManager\Types\File::class, "path" => "default_files/test/", "private" => false, "date_time_prefix" => true, "use_file_name_to_upload" => false, "secret" => "ashkdsjka#sdkdjfsj22188455$$#$%dsDFsdf", "download_link_expire" => 160, // minutes ], "image" => [ "provider" => \AliGhale\FileManager\Types\Image::class, "path" => "images/upload/documents/", "sizes" => ["16", "24", "32", "64", "128", "320"], "thumb" => "320" ], "profile" => [ "parent" => "image", "path" => "images/upload/profiles/", "date_time_prefix" => false, ], ], ];
配置参数
name | type | description |
---|---|---|
provider | string (class name) |
提供者类名,必须是 AliGhale\FileManager\BaseType 的扩展 |
path | string |
文件上传路径 |
private | boolean |
是否私有,如果为 true 则将文件上传到存储文件夹,否则如果为 false 则将文件上传到公开文件夹 |
date_time_prefix | boolean |
如果为 true 则使用 /{year}/{month}/{day} 前缀上传文件 |
use_file_name_to_upload | boolean |
如果为 true 我们使用文件的原始名称,否则我们生成一个随机名称 |
secret | string |
生成下载链接和下载文件的密钥 |
download_link_expire | boolean |
生成的下载链接过期时间 |
parent | string |
父类型名称 |
sizes | array |
尺寸数组,仅适用于图像类型 |
thumb | string 或 number |
缩略图图像的尺寸,仅适用于图像类型 |
开始使用
上传文件
$file = request()->file('filename'); $upload = File::upload($file); // get file uploaded path $filePath = $upload->getFilePath(); // get file name $fileName = $upload->getName();
您可以使用以下方法
方法 | description |
---|---|
useFileNameToUpload($status = true) |
如果为 true 我们使用文件的原始名称,否则我们生成一个随机名称 |
type($type = null) |
更改上传类型,如果为 null 则使用默认类型 |
getFile($name = null) |
通过名称获取文件并返回一个 \AliGhale\FileManager\Models\File |
setPath($path) |
设置文件上传路径 |
delete($filename) |
通过此提供者类型删除文件 |
getUploadPath() |
获取上传路径 |
dateTimePrefix($value = true) |
如果为 true 则使用 /{year}/{month}/{day} 前缀上传文件 |
setName(string $name) |
设置文件名 |
setFormat(string $format) |
设置文件上传格式 |
isPrivate() |
如果您调用此方法,则将文件上传到存储文件夹,并且您没有权限访问此文件 |
isPublic() |
如果您调用此方法,则将文件上传到公开文件夹,并且可以访问此文件 |
示例
$file = request()->file('filename'); $upload = \AliGhale\FileManager\Facades\File::setName('your specific name') ->isPrivate() ->setFormat('png') ->dateTimePrefix() ->upload($file); // get file uploaded path => if is public you can use it for download dd($upload->getFilePath());
$file = File::getFile("file uploaded name"); $file->name; $file->path; $file->type; // config file selected type $file->isPrivate; $file->isPublic; $file->generateLink(); // return response download // $file->download();
更改类型
$file = request()->file('filename'); $upload = \AliGhale\FileManager\Facades\File::type("type_name") // type name in config file (filemanager.php) ->upload($file);