Reputation: 2485
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?
Upvotes: 0
Views: 105
Reputation: 977
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.
Upvotes: 1