PhoneGap FileTransfer无法使用PHP?

时间:2014-05-23 06:56:29

标签: php android cordova phonegap-plugins phonegap-build

我正在尝试将配置文件图片从Android手机上传到远程mysql数据库表,其中包含使用php的BLOB类型的列。

但是下面的文件传输代码根本不起作用?当我点击getimage按钮时,我甚至无法选择图片,它只是不做任何事情?

另外,我是以正确的方式调用php吗?

我正在使用PhoneGap Build构建我的应用程序我是否需要在config.xml文件中添加特定于filetransfer的内容?

1.index.html

<!DOCTYPE html>
<html>
   <head>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
      <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
      <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
      <script>
         function onDeviceReady() {

           }

          function getImage() {
                   // Retrieve image file location from specified source
                   navigator.camera.getPicture(uploadPhoto, function(message) {
                                               alert('get picture failed');
                                               },{
                                               quality: 50, 
                                               destinationType: navigator.camera.DestinationType.FILE_URI,
                                               sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
                                               }
                                               );

               }

         function uploadPhoto(imageURI) {
               var options = new FileUploadOptions();
               options.fileKey="file";
               options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
               options.mimeType="image/jpeg";

               var params = new Object();

               options.params = params;

               var ft = new FileTransfer();
               ft.upload(imageURI, encodeURI("http://www.xyz.uni.me/php/updateProfilePicture.php"), win, fail, options);
           }


           function win(r) {
               console.log("Code = " + r.responseCode);
               console.log("Response = " + r.response);
               console.log("Sent = " + r.bytesSent);
           }

           function fail(error) {
               alert("An error has occurred: Code = " + error.code);
               console.log("upload error source " + error.source);
               console.log("upload error target " + error.target);
           }

      </script>
   </head>
   <body>
      <button onclick="getImage();">Upload a Photo</button>
   </body>
</html>

2.updateProfilePicture.php文件

<?php 

$con = mysqli_connect("localhost", "xyzusername", "xyzpassword", "xyzdatabase", "3306");
mysqli_select_db($con, "xyzdatabase");

$email = 'xyz@gmail.com';

$stmt = $con->prepare('UPDATE  profileinformation SET Image = ? Where email = ? ');
$null = null;
$stmt->bind_param('bs',$null, $email);
$stmt->send_long_data(0, file_get_contents($_FILES['file']['tmp_name']));
$stmt->execute();

if ($stmt->errno) {
        echo "FAILURE!!! " . $stmt->error;
}

$stmt->close(); 
?>

0 个答案:

没有答案