laravel - way to store base64 images
installation kit
composer require melihovv/base64-image-decoder
Usage example
After decoding the package, you can customize the file name and use Storage::put to save the image file under storage\app.
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use Melihovv\Base64ImageDecoder\Base64ImageDecoder; try { $dataUri = 'data:image/gif;base64,R0lGODlhLAH6AOZ/AMyokXJMK0uE...'; $decoder = new Base64ImageDecoder($dataUri, ['jpeg', 'jpg', 'png', 'gif']); $fileName = strtoupper(Str::uuid()) . "." . $decoder->getFormat(); Storage::put($fileName, $decoder->getDecodedContent()); } catch (\Exception $e) { dd($e->getMessage()); }
0 Comments