PHP code example of hasanhawary / media-manager
1. Go to this page and download the library: Download hasanhawary/media-manager 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/ */
hasanhawary / media-manager example snippets
use HasanHawary\MediaManager\Facades\Media;
return [
'disk' => null,
'path' => 'files',
'visibility' => 'public',
'fallback_extension' => 'jpg',
'naming_strategy' => 'uuid',
'chunks' => [
'directory' => 'chunks',
'uploads_directory' => 'uploads',
],
'routes' => [
'enabled' => true,
'prefix' => 'media-manager',
'middleware' => [],
'name' => 'media-manager.',
],
];
use HasanHawary\MediaManager\Facades\Media;
$path = Media::upload($request->file('avatar'), 'uploads/avatars');
$url = Media::url($path);
$path = Media::on('public')
->visibility('private')
->fallbackExtension('png')
->generateName('uuid')
->upload($request->file('photo'), 'uploads/photos');
Media::upload($request->file('avatar'), 'avatars');
Media::upload($base64Image, 'images');
Media::fromUrl('https://example.com/photo.jpg', storedLocal: true)->to('images')->store();
Media::upload(file_get_contents('report.txt'), 'documents');
Media::upload(storage_path('app/temp/logo.png'), 'logos');
Media::generateName('hash')->upload($file, 'files');
Media::generateName('timestamp')->upload($file, 'files');
Media::keepOriginalName()->upload($file, 'files');
Media::withName(fn () => 'invoice_'.time().'.pdf')->upload($file, 'invoices');
$path = Media::replace($user->avatar)
->upload($request->file('avatar'), 'uploads/avatars');
$user->update(['avatar' => $path]);
$pathOrChunkNumber = Media::chunk([
'file_name' => $request->input('file_name'),
'chunk_number' => $request->integer('chunk_number'),
'chunk_file' => $request->file('chunk_file'),
'is_final' => $request->boolean('is_final'),
'user_id' => $request->user()?->id,
'directory' => 'videos',
]);
Media::url($path);
Media::on('public')->url($path);
Media::on('s3')->temporaryUrl($path, 10);
Media::on('s3')->signedUrl($path, now()->addDay());
$meta = Media::meta('uploads/docs/report.pdf');
$meta->path();
$meta->url();
$meta->size();
$meta->mime();
$meta->extension();
$meta->basename();
$meta->filename();
$meta->dirname();
$meta->lastModified();
$meta->hash();
$meta->dimensions();
$meta->toArray();
Media::exists($path);
Media::delete($path);
Media::safeDelete($path);
use HasanHawary\MediaManager\Support\FileNameGenerator;
use HasanHawary\MediaManager\Support\PathNormalizer;
use HasanHawary\MediaManager\Support\RemoteMediaFetcher;
$name = FileNameGenerator::generate('txt', 'uuid');
$path = (new PathNormalizer())->directory('../unsafe');
$isPublicUrl = (new RemoteMediaFetcher())->isValidUrl('https://example.com/file.jpg');
bash
php artisan vendor:publish --tag=media-manager-config