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

Open
opened 2018-03-13 10:56:26 +00:00 by fischerito · 1 comment
fischerito commented 2018-03-13 10:56:26 +00:00 (Migrated from github.com)

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.

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 2018-04-29 04:26:42 +00:00 (Migrated from github.com)

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

change name $_POST to anything, and try vardump. look at developer option
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#988