Вы можете отправить его, используя FormData()
HTML
<input name="image" type="file" (change)="file($event)" required>
TS
file(event) {
let elem = event.target;
if(elem.files.length > 0) {
let formData = new FormData();
formData.append('file', elem.files[0], elem.files[0].name)
this._auth.uploadImg(formData) //send it to service so you can make http call and send it as a post method to the backend
.subscribe((data) => {
console.log(data) //Image name
},
(error) => {
console.log('error: ', error)
})
}
}
PHP
$imageFolder = "images/";
if(isset($_FILES)) {
if(preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $_FILES['file']['name'])){ //checking file name in english
echo json_encode('Invalid name');
exit();
}
if(!in_array(strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png"))){ // checking file extension
echo json_encode('Invalid extension');
exit();
}
$name = explode('.', $_FILES['file']['name']);
$ext = end($name);
$name = reset($name).md5($date).'.'.$ext;
$filetowrite = $imageFolder . $name;
move_uploaded_file($_FILES['file']['tmp_name'], $filetowrite); //move the image to the directory defined in $imageFolder variable above
echo json_encode($name); //return current image name to angular
exit();
} else {
echo json_encode('No such file');
exit();
}