Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ajax和post将base64string传递到php文件_Php_Jquery_Ajax - Fatal编程技术网

使用ajax和post将base64string传递到php文件

使用ajax和post将base64string传递到php文件,php,jquery,ajax,Php,Jquery,Ajax,在这里使用移动应用程序,我使用post方法将图像编码数据发送到php文件,并从php文件中获取图像url。这里的问题是,我在使用ajax发送字符串时没有得到正确的图像。当我手动放置图像数据时,我可以查看图像,但是当使用ajax调用发送图像数据时,无法查看图像 <?php //$image = $_POST['uploadedfile'];//not working if an ajax call is made what is the issue here $image

在这里使用移动应用程序,我使用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';
    }
?>

请显示ajax调用。另外,ajax请求是从php脚本所在的同一域发送的吗?在任何人能够真正回答这个问题之前,您需要在您的问题中添加1。发布数据的JavaScript,以及2。收到了
$\u POST['uploadedfile']
打印文件。请注意:您永远不想自己构建JSON,例如,将有效的JSON字符串组合在一起。出错的可能性太大了。相反,使用数组,并在最后使用保证有效结果的
JSON\u encode()
将其转换为JSON。您显示的ajax调用是否直接来自您的代码?因为url属性中有double
.php
。“url太长”问题表明您正在执行一个
GET
请求,而不是
POST
请求。这是一个编辑错误。我们只有filename.php…从ajax获取的值和在php文件中回显的值都是相同的值,但图像没有正确显示
$.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");

}
});