Created
September 29, 2020 03:00
-
-
Save lpirir/ffcb777034147316521694acab793eb1 to your computer and use it in GitHub Desktop.
This code store a base64 image using the Laravel's filesytem (File Storage) methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$image_64 = $data['photo']; //your base64 encoded data | |
$extension = explode('/', explode(':', substr($image_64, 0, strpos($image_64, ';')))[1])[1]; // .jpg .png .pdf | |
$replace = substr($image_64, 0, strpos($image_64, ',')+1); | |
// find substring fro replace here eg: data:image/png;base64, | |
$image = str_replace($replace, '', $image_64); | |
$image = str_replace(' ', '+', $image); | |
$imageName = Str::random(10).'.'.$extension; | |
Storage::disk('public')->put($imageName, base64_decode($image)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hola trato de usar esté código y me da el siguiente error "Undefined array key 1"