项目作者: AliGhaleyan

项目描述 :
laravel file uploader
高级语言: PHP
项目地址: git://github.com/AliGhaleyan/laravel-file-manager.git
创建时间: 2020-02-24T18:08:56Z
项目社区:https://github.com/AliGhaleyan/laravel-file-manager

开源协议:MIT License

下载


Laravel File Manager

Installation:

  1. composer require alighale/laravel-file-manger

You must add the service provider to config/app.php

  1. 'providers' => [
  2. // for laravel 5.8 and below
  3. \AliGhale\FileManager\FileManagerServiceProvider::class,
  4. ];

Publish your config file and migrations

  1. php artisan vendor:publish

Config:

config/filemanager.php
``` 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,
],
],
];

  1. ### Config Parameters
  2. | name | type | description |
  3. |---------------|--------------|---------------------------|
  4. | provider | `string (class name)`| provider class name, must be extended of `AliGhale\FileManager\BaseType` |
  5. |path | `string` | file upload path |
  6. |private | `boolean` | is private or no if is `true` so upload file in storage folder else if is `false` so upload file in public folder |
  7. |date_time_prefix|`boolean` | if is `true` so upload file with `/{year}/{month}/{day}` prefix|
  8. |use_file_name_to_upload| `boolean`| if is `true` we use of the file original name else we generate a random name|
  9. |secret |`string` | secret key for generate download link and download file|
  10. |download_link_expire|`boolean`|generated download link expire time|
  11. |parent |`string` |parent type name |
  12. |sizes |`array` |array of sizes and there are only for image type|
  13. |thumb |`string` or `number`|size for thumb image and this is only for image type|
  14. ## Lets start to use:
  15. #### Upload a file:
  16. ```php
  17. $file = request()->file('filename');
  18. $upload = File::upload($file);
  19. // get file uploaded path
  20. $filePath = $upload->getFilePath();
  21. // get file name
  22. $fileName = $upload->getName();

You can use of this methods:

method description
useFileNameToUpload($status = true) if is true we use of the file original name else we generate a random name
type($type = null) change type for upload if is null so use of default type
getFile($name = null) get file by name and return a \AliGhale\FileManager\Models\File
setPath($path) set file upload path
delete($filename) delete the file help by this provider type
getUploadPath() get upload path
dateTimePrefix($value = true) if is true so upload file with /{year}/{month}/{day} prefix
setName(string $name) set file name
setFormat(string $format) set format for file upload
isPrivate() if you call this so upload file in storage folder and your you don’t have permission to access this file
isPublic() if you call this so upload file in public folder and has access to this file

Examples:

  1. $file = request()->file('filename');
  2. $upload = \AliGhale\FileManager\Facades\File::setName('your specific name')
  3. ->isPrivate()
  4. ->setFormat('png')
  5. ->dateTimePrefix()
  6. ->upload($file);
  7. // get file uploaded path => if is public you can use it for download
  8. dd($upload->getFilePath());
  1. $file = File::getFile("file uploaded name");
  2. $file->name;
  3. $file->path;
  4. $file->type; // config file selected type
  5. $file->isPrivate;
  6. $file->isPublic;
  7. $file->generateLink();
  8. // return response download
  9. // $file->download();

Change type:

  1. $file = request()->file('filename');
  2. $upload = \AliGhale\FileManager\Facades\File::type("type_name") // type name in config file (filemanager.php)
  3. ->upload($file);