Save file with original extension

Posted 1 month ago by atfinho

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 !

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.