2

I know there are so many solutions for decode base64 image. But any of them didn't work for me.

I have the Base64 image data and i need to convert it to a png file and save it to the local directory. I tried the following code which i got from here. But it didnt work for me. Please help me to get this done..

    define('UPLOAD_DIR', 'images/');
$base64string = "data:image/png;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBB...";
        $img = $base64string;
        $img = str_replace('data:image/png;base64,', '', $img);
        $img = str_replace(' ', '+', $img);
        $data = base64_decode($img);
        $file = UPLOAD_DIR . uniqid() . 'txtimg.png';
        $success = file_put_contents($file, $data);
        print $success ? $file : 'Unable to save the file.';

When i execute the script its getting the error message Unable to save. Then i gave full permission for the users. But still no luck. I tried to save a simple text file through file_put_contents() ; it worked.

I'm using IIS 8 on Windows Azure Server.

0 Answers0