twom/laravel-file-manger

There is no license information available for the latest version (1.1.3) of this package.

Upload file and download it :)

1.1.3 2020-07-26 06:08 UTC

This package is auto-updated.

Last update: 2024-09-26 15:24:31 UTC


README

Installation:

composer require twom/laravel-file-manger

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

'providers' => [
	 // for laravel 5.8 and below
	 \Twom\FileManager\FileManagerServiceProvider::class,
];

Publish your config file and migrations

php artisan vendor:publish

Config:

config/filemanager.php

return [  
  "type" => "default",  
  
  "types" => [  
	  "default" => [  
		  "provider" => \Twom\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" => \Twom\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,
      ],  
  ],  
];

Config Parameters

Lets start to use:

Upload a file:

$file = request()->file('filename');
$upload = File::upload($file);

//	get file uploaded path
$filePath = $upload->getFilePath();

//	get file name  
$fileName = $upload->getName();

You can use of this methods:

Examples:

$file = request()->file('filename');  
$upload = \Twom\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();

Change type:

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