如何在离子中使用php上传文件?

时间:2018-04-30 10:16:48

标签: php angular ionic-framework

我想以离子方式上传文件。我按照此链接 - https://www.youtube.com/watch?v=3f0oLzDazS0 但我想通过PHP上传文件。我怎么能调用php文件。请指教。

html代码

<button ion-button (click)="choose()">Upload</button>

ts代码

choose()
  {
    this.filechooser.open().then((uri) => {
      alert(uri);

      this.file.resolveLocalFilesystemUrl(uri).then((newUrl) =>{
        alert(JSON.stringify(newUrl));

        let dirPath = newUrl.nativeURL;
        let dirPathSegments = dirPath.split('/');
        dirPathSegments.pop();
        dirPath = dirPathSegments.join('/');

        this.file.readAsArrayBuffer(dirPath,newUrl.name).then((buffer =>{
          this.upload(buffer,newUrl.name);
        }));
      });
    }); 
  }

upload(buffer , name)
  { }