$ext = $image->getClientOriginalExtension(); // method returns extension.
Instead of .png, use . $ext
Hey guys
I'm trying to upload an image via restful api.. the code below works only when image is " PNG " .. otherwise I couldn't access to it.. how can I upload any image no matter is the extension?
$image = $request->input('image'); // your base64 encoded
$image = str_replace('data:image/png;base64,', '', $image);
$image = str_replace(' ', '+', $image);
$imageName = str_random(10).'.'.'png';
\File::put(public_path(). '/images/' . $imageName, base64_decode($image));
Thank you in advance !
Thank you guys
I just added this following code and it worked properly
/**Extract file extension */
$img = explode(',', $image);
$ini =substr($img[0], 11);
$type = explode(';', $ini);
echo $type[0]
/** $type[0] type image */
Please or to participate in this conversation.