我正在尝试通过ajax将base64数据发送到PHP脚本来解码并保存图像。
这是我非常基本的PHP脚本:
$ajaxData = $_POST['data1'];
$base64img = str_replace('data:image/jpeg;base64,', '', $ajaxData);
$data = base64_decode($base64img);
file_put_contents("img.jpg", $data);
我从ajax获取数据,base64数据以:
开头数据:图像/ JPEG; BASE64,/ 9J / 4AAQSkZJRgABAQAAAQABAAD / 2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD / 2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD / wAARCANSA1IDASIAAhEBAxEB / 8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL / 8QAtRAAAgEDAwIEAwU ......
它似乎解码它,但是当我运行它时,没有任何内容被写入目录。我做错了什么或者我怎么能诊断出来?
谢谢!