PHP code example of erlandmuchasaj / laravel-file-uploader
1. Go to this page and download the library: Download erlandmuchasaj/laravel-file-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/ */
erlandmuchasaj / laravel-file-uploader example snippets
use ErlandMuchasaj\LaravelFileUploader\FileUploader;
Route::post('/files', function (\Illuminate\Http\Request $request) {
$max_size = (int) ini_get('upload_max_filesize') * 1000;
// FileUploader::images() get all image extensions ex: jpg, png, jpeg, gif, etc.
// FileUploader::documents() get all documents extensions ex: 'csv', 'html', 'pdf', 'doc', 'docx', 'ppt' etc.
$extensions = implode(',', FileUploader::images());
$request->validate([
'file' => [
' ->with('success', __('File has been uploaded.'))
->with('file', $response);
})->name('files.store');
/**
* $response = [
* "type" => "image"
* "extension" => "png"
* "_extension" => "png"
* "name" => "blog3"
* "original_name" => "blog3.png"
* "size" => 549247
* "mime_type" => "image/png"
* "dimensions" => "670x841"
* "path" => "uploads/1/image/blog3_1678118034.png" // <==
* "url" => "/storage/uploads/1/image/blog3_1678118034.png"
* "user_id" => 1
* "disk" => "local"
* "visibility" => "public"
* "uuid" => "dd5889c0-5057-49ef-a6ef-e3da961a47d1"
* ]
*/
$path = 'uploads/1/image/blog3_1678118034.png'; // the path of the image where is stored.
$response = FileUploader::get($path); // get file as StreamedResponse
$response = FileUploader::getFile($path); // get file as content.
$response = FileUploader::url($path); // full path url - /storage/uploads/1/image/blog3_1678118034.png
$response = FileUploader::path($path); // C:\wamp\www\laravel-app\storage\app\uploads/1/image/blog3_1678118034.png
$response = FileUploader::meta($path); // metadata about the file.
/**
* [
* "path" => "C:\wamp\www\laravel-app\storage\app\uploads/1/image/blog3_1678118034.png"
* "url" => "/storage/uploads/1/image/blog3_1678118034.png"
* "visibility" => "public"
* "mimeType" => "image/png"
* "size" => "536.37 KB"
* "last_modified" => "1 hour ago"
* "name" => "blog3_1678118034.png"
* "pathinfo" => [
* "dirname" => "uploads/1/image"
* "basename" => "blog3_1678118034.png"
* "extension" => "png"
* "filename" => "blog3_1678118034"
* ]
* ]
*/
$response = FileUploader::download($path, 'something_nice'); // download the file as StreamedResponse
$response = FileUploader::getVisibility($path); // file visibility when applicable private/public
$response = FileUploader::setVisibility($path, 'private'); // change file visibility
$response = FileUploader::remove($path); // delete a file
$size = 549247;
FileUploader::formatBytes($size); // "536.37 KB"
FileUploader::convertBytesToSpecified($size, 'KB'); // 536.37KB
FileUploader::convertBytesToSpecified($size, 'MB'); // 0.52MB
bash
php artisan vendor:publish --provider="ErlandMuchasaj\LaravelFileUploader\FileUploaderServiceProvider"