Problem fixed. The image is now viewable. I forgot to change this str_replace('data:image/png;base64,', '', $img)
to this str_replace('data:image/jpeg;base64,', '', $img),
because the type of my image is jpeg.
Image not viewable in folder
Вопрос
I have an image encoded in a base64 string and i need it to save on a folder as a image. This is the code:
$img = Input::get('myField');
define('UPLOAD_DIR', 'C:/wamp/www/laravel/dentalRoyale/public/assets/profile/');
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);
Yeah, it saves on the profile folder. But i can't open the image which i badly need. How can i fix this? Thanks
Решение 2
Другие советы
Firstly, are you absolutely certain that it's a png?
Secondly, $img = str_replace(' ', '+', $img);
isn't needed. If anything, you'd need to do that in reverse if the string is uri encoded.
Try commenting out that line and checking that it's actually a PNG.
Не связан с StackOverflow