在这里使用移动应用程序,我使用post方法将图像编码数据发送到php文件,并从php文件中获取图像URL。这里的问题是,我在使用ajax发送字符串时没有得到正确的图像。当我手动放置图像数据时,我能够查看图像,但是当使用ajax调用发送图像数据时,无法查看图像。
<?php
//$image = $_POST['uploadedfile'];//not working if an ajax call is made what is the issue here
$image ="base64 string of an image here";//working if i place base 64 string here
$binary = base64_decode($image);
$fileName = time() . ".jpeg";
file_put_contents('images/' . $fileName, $binary);
if (file_exists('images/' . $fileName)) {
$myjson12 = "[";
$myjson12.='{';
$myjson12.='"Certificate":"http://domain/demo/images/'.$fileName.'"';
$myjson12.='}';
$myjson12.="]";
echo "$myjson12";
} else {
echo 'FAILURE';
}
?>
当我访问文件网址并发送参数值时,输出将在网址过长时显示:www.domain.com/getdata.php?uploadedfile=base64stringvalue;
这是我的ajax电话
$.ajax({
type: "POST",
url: "www.domain.com/getdata.php",
data: { "uploadedfile": c.toDataURL("image/jpeg") },
// dataType: "json",
success: function (response) {
console.log(response + "Sri");
$("#loadImg").hide();
alert("Success");
},
error: function (data) {
$("#loadImg").hide();
alert("Connection Failed");
}
});