Javascript application/x-www-form-urlencoded在爱奥尼亚和php之间

Javascript application/x-www-form-urlencoded在爱奥尼亚和php之间,javascript,php,angular,ionic-framework,Javascript,Php,Angular,Ionic Framework,我正在创建一个Ionic应用程序,我正在使用一个PHP服务器将用我的移动设备拍摄的照片上传到我的服务器。 我使用的PHP API已经在prod中开发,在我的web版本中没有任何问题,但是当我尝试使用相同的POST请求时,我遇到了问题 我的爱奥尼亚密码: upload_image():Observable<any>{ //This is not the complete string. let _image64 = "data:image/jpeg;base64,/9j

我正在创建一个Ionic应用程序,我正在使用一个PHP服务器将用我的移动设备拍摄的照片上传到我的服务器。 我使用的PHP API已经在prod中开发,在我的web版本中没有任何问题,但是当我尝试使用相同的POST请求时,我遇到了问题

我的爱奥尼亚密码:

upload_image():Observable<any>{
    //This is not the complete string.
    let _image64 = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABALDA4MChAODQ4SERATGC";
    let params = `image64_str=${_image64}`;
    let headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');
    let httpOptions = {headers};
    return this.http.post<any>("http://API_URL",params,httpOptions);
}
upload_image():可观察{
//这不是完整的字符串。
让_image64=“数据:image/jpeg;base64,/9j/4aaqskzjrgabaaaqaabaad/2wbdabalda4mschaodq4seratgc”;
设params=`image64_str=${{u image64}`;
let headers=new-HttpHeaders().set('Content-Type','application/x-www-form-urlencoded');
让httpOptions={headers};
返回此.http.post(“http://API_URL“,参数,httpOptions);
}
我的PHP代码:

<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header('Content-type: application/x-www-form-urlencoded');
$strimg = $_POST['image_str64'];
$image_str = substr($strimg ,strpos($strimg , ',')+1); //To avoid "data:image/jpeg;base64," from the 64string
$data = base64_decode($image_str);
//
//rest of code to check the format, directory and so one.
//

在你的爱奥尼亚+PHP应用程序中,尝试将
内容类型设置为
图像/jpeg


最后,我决定通过更改我的API,以便使用其他选项,如ionic提供的uploadfile。

我会尝试,但我想我不得不更改我的API文档,我不希望这样做。
<b>Warning</b>:  imagecreatefromstring(): gd-jpeg: JPEG library reports unrecoverable error:  in <b>/API/test.php</b> on line <b>57</b>
<b>Warning</b>:  imagecreatefromstring(): Passed data is not in 'JPEG' format in <b>/API/test.php</b> on line <b>57</b>
<b>Warning</b>:  imagecreatefromstring(): Couldn't create GD Image Stream out of Data in <b>/API/test.php</b> on line <b>57</b>