过去2天我在PHP服务器上运行了相机 . 服务器上的代码工作正常,但 $_FILES var为空 .

我的问题与此处描述的问题类似,也没有解决方案Corodova file transfer not working after updating to ionic 2 RC0 .

我的应用程序连接到相机,拍照,加载并发送到服务器 . 这个过程需要几秒钟 . 我恢复上传没有错误,但 $_FILES[""] 是空的 .

我尝试了几种方法,包括使用 Headers 和删除 Headers 但没有任何效果 . 每次都出现同样的问题:服务器上没有上传文件 .

技术:

  • Cordova CLI:6.1.1

  • Ionic Framework版本:2.0.0-rc.2

  • 离子CLI版本:2.1.4

  • Ionic App Lib版本:2.1.2

  • 离子应用程序脚本版本:0.0.44

  • 操作系统:Windows 7 SP1

  • 节点版本:v6.2.0

我的代码:

进口:

import { Camera } from 'ionic-native';
import { Transfer } from 'ionic-native';

camera.html:

<button ion-button color="dark" (click)="takePhoto()">Open camera </button>
<img [src]="imageURL" *ngIf="imageURL" />
<br>imageURL={{imageURL}}
<br><button ion-button color="dark" (click)="upload1()">Upload image</button>

camera.ts:

takePhoto(){
    Camera.getPicture().then((imageData) => {
       this.imageURL = imageData;
    }, (err) => {
       console.log(err);
    });
}

upload1(){
    const ft = new Transfer();
    var options = {
         fileKey: 'file',
         fileName: 'file_name',
         headers: {
             'Content-Type':'multipart/form-data'
         }
    }
    ft.upload(this.imageURL,encodeURI("https://www.myserver.ro/my_file.php?op=upload"),options)

    .then((data) => {
        // success
        alert("OK:"+this.imageURL);
        }, (err) => {
            // error
            alert("ERROR ON UPLOAD: "+err.toString()+"\n picture url: "+this.imageURL);  
        })
}

非常感谢 .