1. Go to this page and download the library: Download sands/uploadable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sands / uploadable example snippets
use Sands\Uploadable\UploadableTrait;
class Task extends Model
{
use UploadableTrait;
...
}
protected $uploadableConfig = [
// handle <input type="file" name="images"/> or <input type="file" name="images[]" multiple/>
'images' => [
'fix-image-orientation', // fixes the image orientation
'save', // saves the image prefixed wth "original-"
'resize-image:800', // resize the image to 800px width, maintain aspect ratio
'save:medium', // saves the image prefixed with "medium-"
'resize-image:400', // resize the image to 400px width, maintain aspect ratio
'save:small', // saves the image prefixed with "small-"
'thumbnail-image:140', // creates a 140px x 140px thumbnail of the image, resized then center cropped
'save:thumbnail', // saves the image prefixed with "thumbnail-"
],
// handle <input type="file" name="images[main]"/> use 'dot' notation
'images.main' => [
...
],
];
public static function boot()
{
self::saved(function (Task $task) {
$task->attachFiles();
});
self::deleted(function (Task $task) {
$task->detachFiles();
});
}
namespace App\Filters\RotateImage;
use Sands\Uploadable\FilterInterface;
class RotateImage implements FilterInterface
{
public function process($type, $file, $model)
{
$image = app('image')->make($file->getPathname());
$image->rotate($this->degrees);
$image->save();
}
public function __construct($degrees = 0)
{
$this->degrees = $degrees;
}
}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Filters\RotateImage;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
app('uploadable')->registerFilter('rotate-image', RotateImage::class);
}
....
}
use Sands\Uploadable\UploadableTrait;
class Task extends Model
{
use UploadableTrait;
protected $uploadableConfig = [
'images' => [
'rotate-image:63', // rotate the image by 63 degrees
'save', // save the image
],
];
...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.