首页 > 解决方案 > 如何从 Ionic 接收 PHP 中的 $ FILES?

问题描述

我正在使用 FormData 将带有角度的 ionic 文件发送到 PHP,但是在 PHP 后端中,当您使 var dump $_FILES 显示为空时。

这是我在 .ts 中的代码:

  file: File;
  changeListener($event): void {
    this.file = $event.target.files[0];
    console.info(this.file); //First console info
    const formData = new FormData();
    const blobFile = new Blob([this.file], { type: this.file.type });

    formData.append("file", blobFile, "filename");
 
    this.myService.testing(formData).subscribe( resp => {
        
      },(error)=>{
       
        console.info(error);
        
        
      })  

  }

在服务中:

testing(data) {

return this.http.post(url, body, {headers: {'Content-Type': 'application/x-www-form-urlencoded'}})

}

PHP 支持:

$postdata = file_get_contents("php://input"); // this shows me the contents of the file
var_dump($_FILES); // returns an empty array

那么,我的错误是什么?我是从 Ionic 发送糟糕还是我在 PHP 中变得糟糕?

我正在使用codeigniter 3

谢谢 !

标签: phpcodeigniterionic-framework

解决方案


推荐阅读