0

i am trying to upload file in Windows 8 tablet as follows

var uri = new Windows.Foundation.Uri( uriString );
var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader();
uploader.method = "POST";

uploader.setRequestHeader( "file", file.name );
uploader.setRequestHeader( "Content-Type", "multipart/form-data" );
upload = uploader.createUpload( uri, file );

i am calling server script which is written in PHP and that is as follows

<?php
if ($_FILES["file"]["error"] > 0) {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>

but when i execute the code in windows 8 , its showing me following error

Notice: Undefined index: file in upload.php

this is happening because i am missing something wrong in setting up the request headers uploader.setRequestHeader , so can anyone tell me what request headers i should set it to make it work.

Stígandr
  • 2,874
  • 21
  • 36
Hunt
  • 8,215
  • 28
  • 116
  • 256
  • `uploader.setRequestHeader( "Content-Type", "application/octet-stream" );` Just a shot in the dark here. JS is not my ballgame. [linked?](http://stackoverflow.com/a/20509354/2285592) – Stígandr Oct 02 '14 at 19:50

1 Answers1

0

I'm trying to fix this too, because I'm calling my php file, but I can't get the file. Anyway, you have to put another function to make it working

upload .startAsync().then(
  function succes(resultat) {
    console.log('file uploaded');
  },

  function erreur(resultat) {
    console.log('there is an error');
  },

  function progression(resultat) {
    var pourcentage = Math.round(resultat.progress.bytesSent * 100 / resultat.progress.totalBytesToSend);
    console.log(pourcentage + ' %');
  }
);

Let me know if you find out how to make the php work !

H4mm3R
  • 245
  • 4
  • 15