2014-06-11 33 views
0

上传使用的WinRT,winJS,JAVASCRIPT & HTML 5.WinJS.xhr blob图像不显示在PHP服务器?

我生成从在画面图像的斑点,并且经由winJS.xhr上RESTful的API将其发送到服务器从取胜8.1片剂的图片我有一个功能,捕获该帖子并将其保存到Linux服务器上的位置。

问题是图像是空的或不可读的。问题是在PHP中,我测试了不同的选项,没有使得img可读?

如何获取img?

的WinRT代码:

function uploadImg(){ 
var url2="http://serverurl/sr/uploadpicture"; 

var picturesLibrary = Windows.Storage.KnownFolders.picturesLibrary; 
picturesLibrary.getFileAsync("test.bmp").then(

function completeFile(file) { 
     return file.openAsync(Windows.Storage.FileAccessMode.readWrite); 
}).then(
    function completeStream(stream) { 
    // Do processing. 
    var blob = MSApp.createBlobFromRandomAccessStream("image/bmp", stream); 
    //document.getElementById('imgCapture').src=blob; 

    var fd = new FormData(); 
    fd.append('test', 'lalalala'); 
    fd.append('data', blob); 
    return WinJS.xhr({ type: "POST", url: url2, data: fd }); 
}).then(
    function (request) { 
     document.getElementById('txteserver').value = "uploaded file:"+request.response; 
    }, 
    function (error) { 
     document.getElementById('txteserver').value= "error uploading file"; 
    }); 
} 

PHP服务器:

/** 
    * 
    * 
    * @url POST /sr/uploadpicture 
    */ 
    public function uploadpicture() 
    { 
    // header("Content-Type: image/bmp"); 
     echo "test"; 
     echo $_POST['test']; 

     $data = $_POST['data']; 
     echo $data; 
     echo 'isset'; 
     echo isset($_FILES['data']); 

     if($_FILES['data']['error'] == 0){ 
      // success - move uploaded file and process stuff here 
     echo 'success'; 
     }else{ 
      // 'there was an error uploading file' stuff here.... 
      echo 'error uploading file'; 
     } 
     echo var_dump($_FILES) ; 

     if (($data)=="") {echo 'empty image ';} 
     else { echo 'Testing uploading picture ';}; 
      $file = "test.bmp"; 
      $img=base64_decode($_FILES['data']['name']); 
      $img2=base64_decode($_POST['data']); 
      file_put_contents($file,img2); 
} 

回声的var_dump($ _ FILES)结果:

{ ["data"]=> array(5) { ["name"]=> string(4) "blob" ["type"]=> string(9) "image/bmp" ["tmp_name"]=> string(14) "/tmp/phpTg4t5M" ["error"]=> int(0) ["size"]=> int(254970) }} 

感谢

回答

0

工作。答案如下:

public function uploadpicture(){ 

if($_FILES['data']['error'] == 0){ 
      // success - move uploaded file and process stuff here 
     echo 'success'; 

     echo var_dump($_FILES) ; 
     move_uploaded_file($_FILES["data"]["tmp_name"],"....server location".$_FILES["data"]["name"]); 

     }else{ 
      // 'there was an error uploading file' stuff here.... 
      echo 'error uploading file'; 
     } 
}