How to save a PNG image server-side, from a base64 data string

后端 未结 15 2354
情话喂你
情话喂你 2020-11-22 03:18

I\'m using Nihilogic\'s \"Canvas2Image\" JavaScript tool to convert canvas drawings to PNG images. What I need now is to turn those base64 strings that this tool generates,

15条回答
  •  灰色年华
    2020-11-22 03:42

    PHP has already a fair treatment base64 -> file transform

    I use to get it done using this way:

    $blob=$_POST['blob']; // base64 coming from an url, for example
    $blob=file_get_contents($blob);
    $fh=fopen("myfile.png",'w'); // be aware, it'll overwrite!
    fwrite($fh,$blob);
    fclose($fh);
    echo ''; // just for the check
    

提交回复
热议问题