PHP code example of browner12 / uploader
1. Go to this page and download the library: Download browner12/uploader 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/ */
browner12 / uploader example snippets php
'providers' => [
browner12\uploader\UploaderServiceProvider::class,
];
php
php artisan vendor:publish --provider="browner12\uploader\UploaderServiceProvider"
php
php artisan vendor:publish --provider="browner12\uploader\UploaderServiceProvider" --tag="config"
php
'base_directory' => '',
php
'original_directory' => 'original',
'optimized_directory' => '',
'thumbnail_directory' => 'thumbnail',
php
'create_optimized' => true,
'create_thumbnails' => true,
php
'document_extensions' => ['pdf', 'doc', 'docx', 'ppt'],
'image_extensions' => ['jpg', 'jpeg', 'gif', 'png'],
'video_extensions' => ['avi', 'mov', 'mp4', 'ogg'],
'audio_extensions' => ['mp3', 'wav'],
'document_mime_types_' => ['application/pdf', 'application/msword'], //other defaults omitted for brevity
'image_mime_types_' => ['image/gif', 'image/jpeg', 'image/png'],
'video_mime_types_' => ['video/avi', 'video/quicktime', 'video/mp4', 'video/ogg'],
'audio_mime_types_' => [ 'audio/mpeg', 'audio/mpeg3', 'audio/wav'],
php
'maximum_upload_size' => 32000000,
php
'optimized_image_quality' => 60,
'optimized_maximum_width' => 1000,
php
'thumbnail_width' => 100,
php
$uploader = new Uploader();
php
public function __construct(UploaderInterface $uploader)
{
$this->uploader = $uploader;
}
php
$this->uploader->document($file, $path, $filename);
$this->uploader->image($file, $path, $filename);
$this->uploader->video($file, $path, $filename);
$this->uploader->audio($file, $path, $filename);
php
public function store(Request $request)
{
try{
if($request->hasFile('image')){
$file = $this->uploader->image($request->file('image'), 'dogs', 1);
}
}
catch(browner12\uploader\UploaderException $e){
//handle any errors here
}
var_dump($file);
}
php
$this->uploader->setDirectory('base', 'newBaseDirectory');
$this->uploader->setDirectory('original', 'newOriginalDirectory');
$this->uploader->setDirectory('optimized', 'newOptimizedDirectory');
$this->uploader->setDirectory('thumbnail', 'newThumbnailDirectory');
$this->uploader->setCreateOptimized(false);
$this->uploader->setCreateThumbnails(false);
$this->uploader->setValidExtensions('image', ['jpg']);
$this->uploader->setValidMimeTypes('image', ['image/jpeg']);
$this->uploader->setMaximumUploadSize(10000000);
$this->uploader->setOptimizedImageQuality(60);
$this->uploader->setOptimizedMaximumWidth(500);
$this->uploader->setThumbnailWidth(200);
php
$this->uploader->reprocess('dogs', true);
sh
php artisan uploader:reprocess dogs,cats --overwrite