valor-software / ng2-file-upload

Easy to use Angular components for files upload
http://valor-software.github.io/ng2-file-upload/
MIT License
1.91k stars 662 forks source link

Upload with PHP backend: $_FILE is not set #988

Open fischerito opened 6 years ago

fischerito commented 6 years ago

Hello,

I have a problem uploading files with Ionic and ng2-file-upload. Apparently server is receiving all adaditional POST parameters, but isset($_FILE['myfile']) returns false.

On submit.html there is: <input type="file" name="myfile" [(ngModel)]="myfile" ng2FileSelect [(uploader)]="uploader" />

On submit.ts: this.uploader.onBuildItemForm = (fileItem: any, form: any) => { form.append('user' , this.user); form.append('token' , this.token); [...] }; this.uploader.uploadAll(); this.uploader.onSuccessItem = (item: any, response: string, status: number, headers: any): any => { if(response){ console.log("submit response: "+JSON.stringify(response)); } }

  this.uploader.onErrorItem = (item: any, response: string,
    status: number, headers: any): any => {
      if(response) {
        console.error('submit error response: ' + JSON.stringify(response));
      }
    }

And on submit.php: $_POST = json_decode(file_get_contents('php://input'), true);

$user = $_POST['user']; $token = $_POST['token'];

if((isset($_FILES["myfile"]))) { [...]

myfile parameter is empty. Do you know what can be happening? Any help is appreciated.

tputraa commented 6 years ago

change name $_POST to anything, and try vardump. look at developer option