get image from base64 string

后端 未结 7 1936
逝去的感伤
逝去的感伤 2020-12-01 10:54

I am trying to take a base64 encoded string and return it as an image in php using $_POST. On line one if I use $_POST[\'imgdata\'] it returns erro

7条回答
  •  攒了一身酷
    2020-12-01 11:36

    Not sure why the regex isn't working for you, I copied the base64 post data and your code and it worked fine. You can try this instead which doesn't use regex and may be a little faster and use less memory.

    $imgstr = $_GET['imgdata'];
    
    list($type, $imgstr) = explode(';', $imgstr);
    list(, $type)        = explode(':', $type);
    list(, $imgstr)      = explode(',', $imgstr);
    $content = base64_decode($imgstr);
    

提交回复
热议问题