首先:将base64码里的“+”号改成"%2B"和“&”改成"%26" 因为在ajax传送时会把他们变成空格 毁坏了数据的正确性

str=str.replace(/\&/g,"%26");
str=str.replace(/\+/g,"%2B");

 

其次:ajax要用post传送,GET无法传送那么多的数据量!

最后:

$filename=date("dMYHis").".png";//要生成的图片名字

function convert_data($data){

 $image = base64_decode( str_replace('data:image/jpeg;base64,', '',$data);  //记得要将base64解码,还有去除base64码前缀
header('Content-Type: image/png');
save_to_file($image);
}
function save_to_file($image){
$fp = fopen($filename, 'w');
fwrite($fp, $image);
fclose($fp);
}

 

相关文章:

  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-11-21
  • 2021-12-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2022-01-08
  • 2022-12-23
相关资源
相似解决方案