Uploader

Uploader

Uploader provides a quick and easy methods to upload files and handling visibility with simple routing.

Moamen Eltouny (Raggi)
PHP Version : >= 7.2 Laravel Version : >= 6.0 License Support
Source Packagist Version Packagist Downloads

Install

Install the latest version using Composer

composer require pharaonic/laravel-uploader
php artisan migrate

(Optional) To publish the config & migrations.

php artisan vendor:publish --tag=laravel-uploader

Configurations

disk Storage Disk (public, s3, ...) - Default : public

path Main Uploading Path - Default : /

route Route URL - Default : /..../hash

user User Model - Default : \App\User::class (depends on laravel version).

prefix Hash Prefixing.


Options

visitable Visits Counter.

private Only Permitted Users .

directory The uploading path - default '/'.

thumbnail . ratio True or False.

thumbnail . width Integer or Null.

thumbnail . height Integer or Null.

Usage

Uploading & Getting

Uploading the file & retrieving it.

function upload(UploadedFile $file, array $options = []) Uploading a file with some options.

// Upload File
$file = upload($request->image, [
	'visitable'	=> true     // custom options
]);

function getUpload(string $hash) Getting uploaded file with Hash.

// Getting Uploaded File with Hash code
$file = getUploaded('5e63885fa771d1.12185481920ncF3...');

// Information
echo $file->hash;                 // File's Hash
echo $file->name;                 // File's Name
echo $file->path;                 // File's Path
echo $file->size;                 // File's Size in Bytes
echo $file->readableSize();       // File's Size [B, KB, MB, ...] (1000)
echo $file->readableSize(false);  // File's Size [B, KiB, MiB, ...] (1024)
echo $file->extension;            // File's Extension
echo $file->mime;                 // File's MIME

echo $file->visits;               // File's visits (Visitable File)

Create Thumbnail

Generating thumbnail from an image.

// Upload File
$file = upload($request->cover, [
	'directory'	=> '/videos',
    'thumbnail' => [            // thumbnail option
        'ratio'     => true,    // with aspect ratio
        'width'     => 500,     // with 500px width
        'height'    => null
    ],
]);

URL & Uploader

Getting file url.

echo $file->url;
$thumb = $file->thumbnail->url;

Getting file uploader object (user).

$user = $file->uploader;

Deleting Uploaded File

Deleting the uploaded file with thumbnail if exists.

$file->delete();

Permits (Private File)

Permitting & Forbidding users.

$permits = $file->permits; // Getting Permits List
$permitted = $file->isPermitted($user); // Checking if permitted (App\User)

$file->permit($user, '2021-02-01'); // Permitting a user
$file->forbid($user); // Forbidding a user