服务器不读取科尔多瓦文件传输选项参数


Server does not read Cordova FileTransfer options params

我在使用科尔多瓦的FileTransfer方法时遇到了问题。该函数以前可以工作,但现在我已经切换了托管服务提供商,并且我与选项对象一起发送的参数不起作用。我使用的上传代码是;

$scope.uploadPhoto = function() {
var img = document.getElementById('image');
var imageURI = img.src;
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
options.headers = {
   Connection: "close"
};
options.chunkedMode = false;
var params = new Object();
//$scope.username =  window.localStorage.getItem("uname");
navigator.geolocation.getCurrentPosition( 
    function(position) { 
      $scope.hideLoading();
      params.lon = position.coords.longitude;
      params.lat = position.coords.latitude;
      params.uname = $scope.username;
      alert(params.lon + ',' + params.lat); 
      options.params = params;
      var ft = new FileTransfer();
      ft.upload(imageURI, "http://file/to/upload.php", win, fail, options, true);
    }, 
    function() { 
      alert('Error getting location'); 
    }
);

}

而服务器端的PHP文件是

$file_url = "''http://path/to/{$new_image_name}''";

//Set up the query and run it
//$myquery = " SELECT  `imgurl`, `lat`, `long` FROM  `pins` ";
$insert = " INSERT INTO pins VALUES ('$file_url', '$lat', '$lon', '$uname' ) ";
$query = mysqli_query($connection, $insert);
//Check the query worked
if ( ! $query ) {
    echo mysql_error();
    die;
}

在我切换服务器提供程序之前,这段代码一直工作正常。它还将 $file_url 参数正确插入到数据库中,因为它是在同一 PHP 文件中设置的,因此与数据库的连接和插入工作正常。问题是使用文件传输选项发送的参数显示为空。

是否有一个没有设置的PHP配置选项,应该是?我真的很感激任何帮助,因为现在我没有想法。

您需要使用请求值设置变量,并在查询中将其连接起来,如下所示:

$file_url = "''http://path/to/{$new_image_name}''";
$lat = $_REQUEST['lat'];
$lon = $_REQUEST['lon'];
$uname = $_REQUEST['uname'];
$insert = "INSERT INTO pins VALUES ('".$file_url."','".$lat."','".$lon."','".$uname."')";

希望这有帮助。