mercredi 31 mai 2017

How to decode and save multiple images sent as base64 string array to server directory?

I am writing a webservice for android app. From the mobile I am sending the image(s) which needs to be decoded and saved as jpg/jpeg/png (any one) format.

The data that will be sent will be a array of base64 which I need to handle it at the backend and save it into a server directory for future references.

To save image my code looks like this. (This is just a test method)

public function testing(Request $request){
    $i=0;
    foreach($request['images'] as $name)
    {
        $i +=1;

        $imagename= 'Image'.$i.'.jpeg';
        $destinationPath = public_path('images');
        $path = 'images/'.$imagename;
        $res = file_put_contents($path, base64_decode($name));
    }
}

This code will create an image with jpeg extension however when I try to open its just giving me this: enter image description here

I think I am missing something.

[Above code is just a demo of uploading a correct file from app.]



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire