Phonegap上传请求为空

时间:2015-09-29 12:44:32

标签: php cordova

我在phonegap中开发了一个小应用程序,最后一个功能,即上传,只是阻止了我。

function uploadFile() {

var options = new FileUploadOptions();

options.fileKey = 'video';
options.fileName = data.title;
options.mimeType = 'video/mp4';
options.httpMethod = 'POST';

var ft = new FileTransfer();
var path = data.mediaItem.fullPath;
var uploadURL = data.pushURL;
var name = data.title;

ft.upload(path,
    uploadURL,
function (result) {
    console.log(result.response + ' ' + result.responseCode);
},
function (error) {
    console.log('Error uploading file ' + error.source + ' ' + error.target + ': ' + error.code + ' ' + error.http_status);
},
options);

}

<?php
file_put_contents('logs.txt', print_r($_FILES));
print_r($_FILES);
$target_dir = "video/";
$target_file = $target_dir . "video";
$uploadOk = 1;
// Check if image file is a actual image or fake image
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 5000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been       uploaded.";
} else {
    echo "Sorry, there was an error uploading your file.";

}
}
?>

服务器收到我的上传请求(响应代码为200),但我的请求为空,然后我的服务器给我一个错误

我在这个错误的1周后就刮了我的头,我无法解决它。

2 个答案:

答案 0 :(得分:0)

此行在服务器上将名称设置为expecto

 options.fileKey = 'video';

但你试图用

来解决它
$_FILES["fileToUpload"]

将fileKey从'video'更改为'fileToUpload'或将$_FILES["fileToUpload"]更改为$_FILES["video"]

答案 1 :(得分:0)

已经尝试了这两个,但我终于找到了解决方案。

你想笑吗?我在php.ini中对POST_MAX_SIZE的修改没有考虑到,我不得不再做一次!

但真的是伙计们,谢谢你的回答:)