I have an existing site built using Laravel. I am "duplicating" the action methods to use Angular, when I duplicated the action that posts a file I didn't get it to work. The $_FILES and $_POST global variables are not being set.
Template: I have an input of type file, when a file is selected I want to send it to the server.
<form enctype="multipart/form-data" [formGroup]="frmUploadFotoUm" (change)="onChange($event)">
<input type="file" [formControl]="frmUploadFotoUm.controls['fuUm']" />
<progress min="0" value="{{progressStatus}}" max="100"></progress>
</form>
Handler:
onChange(event) : void
{
let fileList: FileList = event.target.files;
let file: File = fileList[0];
let formData: FormData = new FormData();
formData.append('imagem', file);
formData.append('imgNum', 1);
formData.append('imgNome', "testandoAngular");
formData.append('tipoAnuncio', "venda");
formData.append('tipoImovel', "casa");
formData.append('imovelId', 361);
formData.append('dirAnuncio', 8);
this.http.post('http://www.example.com/apiuploadfotos/store', formData, {headers: new Headers({ 'Content-Type' : undefined})}
).subscribe(res => {});
}
The Laravel action method:
Here I get "not working" all the time.
public function store(Request $request)
{
if($_FILES)
{
echo "working";
exit();
}
else
{
echo "not working";
exit();
}
}