Package Data | |
---|---|
Maintainer Username: | wielski |
Package Create Date: | 2015-12-26 |
Package Last Update: | 2015-12-26 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-18 03:22:16 |
Package Statistics | |
---|---|
Total Downloads: | 2 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 3 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Install File API
composer require wielski/laravel-fileapi
Set service provider in config/app.php
Wielski\FileApi\FileApiServiceProvider::class,
publish config file
php artisan vendor:publish --tag=fileapi_config
in config/fileapi.php
fill in the storage path, which make routes for you.
'path' => ['/images/event/', '/images/article/'],
it will generate routes like below :
Route::get('/images/event/{filename}', function ($filename) {
$entry = new \Wielski\FileApi\FileApi('/images/event/');
return $entry->getResponse($filename);
});
Route::get('/images/article/{filename}', function ($filename) {
$entry = new \Wielski\FileApi\FileApi('/images/article/');
return $entry->getResponse($filename);
});
set default thumb sizes(by key and value)
'default_thumbs' => ['S' => '96x96', 'M' => '256x256', 'L' => '480x480'],
use \Wielski\FileApi\FileApi;
$fa = new FileApi(); # use default path (as '/images/')
$fa_event = new FileApi('/images/event/'); # initialize it by giving a base path
$fa_article = new FileApi('/images/article/'); # initiate another instance
Default Usage : get unique filename
$file = $fa->save(\Input::file('main_image')); // => wfj412.jpg
Custimize your upload file name
$file = $fa->save(\Input::file('main_image'), 'custom-file-name'); // => custom-file-name.jpg
By default will set three thumbs(equal scaling)
Set custom thumb sizes
$file = $fa
->thumbs([
'S' => '150x100',
'M' => '300x200',
'L' => '450x300'
])
->save(\Input::file('main_image'));
make cropped thumbs
file = $fa->crop()->save(\Input::file('main_image'));
``
$fa->get('wfj412.jpg'); // => get image url of 'L' size
$fa->get('wfj412.jpg', 'M'); // => get image url of 'M' size
$fa->get('wfj412.jpg', 'full); // => get image url of full size
$fa->drop('wfj412.jpg');
$fa->getPath('wfj412.jpg'); // => '/images/event/wfj412.jpg'
if you store your file into cloud storage and you want to get url cloud site, you can use url() method to get it
echo $fa->getUrl('wfjsdf.jpg'); // => "https://s3-ap-northeast-1.amazonaws.com/xxx/xxx/55c1e027caa62L.png"
In your app.php add alias for FileApi class
'FileApi' => Wielski\FileApi\FileApi::class,
Using in Blade:
{{ FileApi::getFile('/images/avatars/', 'image.jpg', 'S') ?: 'default.jpg' }}
Get file content
\Storage::get($fa->getPath('wfj412.jpg'));
Write files
\Storage::put($fa->getPath('wfj412.jpg'));
Get Mime Type
\Storage::mimeType($fa->getPath('wfj412.jpg'));