Question

im trying to save a base64 image into the webserver from a post request, currently my array looks like this.

(
    [0] => Array
        (
            [id] => 0
            [storename] => test
            [notes] => test
            [image] => data:image/jpeg;base64,/9j/4........to long

When i try to update my code to allow for decode and save all i get echo from image is a number.

PHP

            $random = md5(rand());
            $nonerejected[] = array(
                'id' => $data['id'],
                'storename' => $data['storename'],
                'notes' => $data['notes'],
                'image' => $data['image'] == "" ? "" : file_put_contents(''.$random.'.JPG',base64_decode($data['image'])), 

            );

Array output

(
[0] => Array
    (
        [id] => 0
        [storename] => test
        [notes] => test
        [image] => 503331
    )

)

Any ideas guys?

Was it helpful?

Solution

The data:image/jpeg;base64, bit isn't base64, so base64 can't really do anything with it. You'll have to strip this off in order to store your file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top