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

后端 未结 15 2519
情话喂你
情话喂你 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:47

    try this...

    $file = $_POST['file']; //your data in base64 'data:image/png....';
    $img = str_replace('data:image/png;base64,', '', $file);
    file_put_contents('img/imag.png', base64_decode($img));
    

提交回复
热议问题