问题描述
我有一个angular
页面,我在其中加载文件,然后调用PHP
代码将文件上传到我的server
。
Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/test/my-dropzone-app/upload.PHP on line 11
<?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 (将#修改为@)