Windows 8 Windows8使用winjs xhr POST将图像上载到php服务器

Windows 8 Windows8使用winjs xhr POST将图像上载到php服务器,windows-8,Windows 8,我在将图像上载到服务器时遇到问题。 im使用winjs xhr post将图像上载到服务器 问题是php中的上载字段索引未定义错误 请查找以下用于从windows 8上载图像的代码库 function pickImage() { // Create the picker object and set options var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.viewMode = Window

我在将图像上载到服务器时遇到问题。 im使用winjs xhr post将图像上载到服务器

问题是php中的上载字段索引未定义错误 请查找以下用于从windows 8上载图像的代码库

function pickImage() {
// Create the picker object and set options
var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail;
openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary;
// Users expect to have a filtered view of their folders depending on the scenario.
// For example, when choosing a documents folder, restrict the filetypes to documents for your application.
openPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]);

// Open the picker for the user to pick a file
openPicker.pickSingleFileAsync().then(function (file) {
    if (file) {
        // Application now has read/write access to the picked file
        WinJS.log && WinJS.log("Picked photo: " + file.name, "sample", "status");
var fdata = new FormData();
fdata.append('upload_field',file);

       WinJS.xhr({
            type: "post",
            url: "http://localhost/imgupload.php",
            data: fdata,
            // headers: { "Content-type": "application/octet-stream" }


        }).done(function (result) {
            console.log(result.responseText)
        });

        document.getElementById('imgCapture').src
    = window.URL.createObjectURL(file);
    } else {
        // The picker was dismissed with no selected file
        WinJS.log && WinJS.log("Operation cancelled.", "sample", "status");
    }
});
}

下面是我的php代码库

$filesize = filesize($_FILES['upload_field']['tmp_name']); 
echo "The uploaded file size is " . $filesize . " bytes\n";
echo "Stored in: " . $_FILES["upload_field"]["tmp_name"];
$timestamp = time();

if (file_exists("upload/" . $_FILES["upload_field"]["name"]))
  {
  echo $_FILES["upload_field"]["tmp_name"] . " already exists. ";
  }
else
  {   
  $fname = $timestamp.$_FILES["upload_field"]["name"];
  move_uploaded_file($_FILES["upload_field"]["tmp_name"],
  "upload/" . $fname);
  echo "Stored in: " . "upload/" .$fname ;
  }
 echo "image uploaded";

请在这方面帮助我-感谢你的帮助

不应直接使用文件对象。您必须打开该文件并使用它创建blob。 试着这样做:

openPicker.pickSingleFileAsync().then(function (file) {
  file.openAsync(Windows.Storage.FileAccessMode.read).done(function (stream) {
      var blob = MSApp.createBlobFromRandomAccessStream("image/jpg", stream);
      var fdata = new FormData();
      fdata.append('upload_field',blob);

      WinJS.xhr({
          type: "post",
          url: "http://localhost/imgupload.php",
          data: fdata,
          // headers: { "Content-type": "application/octet-stream" }


      }).done(function (result) {
          console.log(result.responseText)
      });
  });
});