尝试使用php在服务器模板中上传文件

问题描述

我有一个angular页面,我在其中加载文件,然后调用PHP代码文件上传到我的server

它不起作用,我对于PHP出现此错误

Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/test/my-dropzone-app/upload.PHP on line 11

PHP代码

<?PHP
  
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT,GET,POST");
header("Access-Control-Allow-Headers: Origin,X-Requested-With,Content-Type,Accept");
   
$folderPath = "http://localhost:8888/test/my-dropzone-app/upload/";
$postdata = file_get_contents("PHP://input");
$request = json_decode($postdata);
   
foreach ($request->fileSource as $key => $value) {
   
    $image_parts = explode(";base64,",$value);
   
    $image_type_aux = explode("image/",$image_parts[0]);
   
    $image_type = $image_type_aux[1];
  
    $image_base64 = base64_decode($image_parts[1]);
  
    $file = $folderPath . uniqid() . '.'.$image_type;
  
    file_put_contents($file,$image_base64);
}

?>

角度:

  onSelect(event) {
      console.log(event);
      this.files.push(...event.addedFiles);

      const formData = new FormData();
  
      for (var i = 0; i < this.files.length; i++) { 
        formData.append("file[]",this.files[i]);
      }
 
      this.http.post('http://localhost:8888/test/my-dropzone-app/upload.PHP',formData)
      .subscribe(res => {
         console.log(res);
         alert('Uploaded Successfully.');
      })
  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...