PHP code example of mattmy / laravel-file-magic
1. Go to this page and download the library: Download mattmy/laravel-file-magic 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/ */
mattmy / laravel-file-magic example snippets
use Mattmy\FileMagic\Facades\FileMagic;
$file = FileMagic::fromUpload($request->file('document'))
->onDisk('local')
->inDirectory('documents')
->named('contract')
->store();
return FileMagic::find($file)->download();
FileMagic::fromUpload($uploadedFile)->store();
FileMagic::fromPath($trustedPath)->store();
FileMagic::fromContent($contents, 'report.pdf')->store();
FileMagic::fromBase64($base64, 'avatar.png')->store();
FileMagic::fromUrl('https://example.com/manual.pdf')->store();
FileMagic::text('Hello')->named('message')->store();
FileMagic::json(['status' => 'ready'])->named('status')->store();
FileMagic::csv($rows)->named('report')->store();
use Mattmy\FileMagic\Enums\CollisionPolicy;
use Mattmy\FileMagic\Enums\FileVisibility;
$file = FileMagic::fromUpload($uploadedFile)
->onDisk('s3')
->inDirectory('accounts/42/contracts')
->named('signed-contract')
->visibility(FileVisibility::Private)
->onCollision(CollisionPolicy::Unique)
->maxSize(10 * 1024 * 1024)
->allowMimeTypes(['application/pdf'])
->withMetadata(['category' => 'contract'])
->ownedBy($user)
->store();
$image = FileMagic::fromUpload($uploadedImage)
->resizeImage(maxWidth: 1200, quality: 80)
->store();
$file = FileMagic::find($uuid)->one();
$files = FileMagic::find([$firstId, $secondUuid])->get();
$exists = FileMagic::find($uuid)->exists();
$url = FileMagic::find($uuid)->url();
$temporaryUrl = FileMagic::find($uuid)->temporaryUrl(now()->addMinutes(15));
$contents = FileMagic::find($uuid)->contents();
$stream = FileMagic::find($uuid)->readStream();
return FileMagic::find($uuid)->download();
return FileMagic::find($targets)->downloadZip('documents');
$deleted = FileMagic::find($targets)->delete();
use Mattmy\FileMagic\Exceptions\FileMagicException;
try {
$file = FileMagic::fromUpload($uploadedFile)->store();
} catch (FileMagicException $exception) {
report($exception);
}
bash
composer vendor:publish --tag=file-magic-config
php artisan vendor:publish --tag=file-magic-migrations
php artisan migrate
bash
php artisan file-magic:audit