我正在尝试通过有角度的httpClient发布方法将单个图像上传到我的php文件中,然后保存到上传文件夹中,但是我无法获取确切的错误,请提供帮助。
HTML和ANGULAR:
<input id="imagePath" type="file" class="input" name="imagePath" (change)="onFileSelect($event)" formControlName="imagePath"/>
Logic:
selectedImage : File;
onFileSelect(event){
this.selectedImage = <File>event.target.files[0];
}
// call http on submit form
onAddImage(){
const fd = new FormData();
fd.append('myFile', this.selectedImage, this.selectedImage.name);
return this.httpClient.post(
'http://localhost/api/upload.php',
newCard,
{
reportProgress: true,
observe: 'events',
headers: new HttpHeaders().set('Content-Type', [])
}
)
.subscribe(
res => console.log(res)
);
}
PHP - server script:
$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["myFile"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["myFile"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
这是我的设置,似乎没有任何事情发生,当我登录.log时,登录名中什么都可以获取我选择的文件(图像)。