2015-09-29 79 views
-1

我正在開發手機上的一個小應用程序,上一個功能,上傳,只是阻止我。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),但我的要求是空的,然後我的服務器我扔一個錯誤

我撓我的頭,因爲這個bug 1周後,我無法解決它。

+0

我認爲這個問題可能是您的目標文件/位置不解決,也不具有延伸。嘗試在你的PHP代碼中改變它,然後看看錯誤是否改變了:'$ target_file = $ target_dir。'/'。「video」。''''$ _ FILES [「fileToUpload」] [「name」]; – andre3wap

回答

0

這條線將名稱設置爲expecto服務器

options.fileKey = 'video'; 

上,但你嘗試用

$_FILES["fileToUpload"] 

變化的FileKey從'video''fileToUpload'$_FILES["fileToUpload"]$_FILES["video"]

0
得到它

已經嘗試了兩種,但我終於找到了解決方案。

你想笑嗎?我在php.ini中修改了POST_MAX_SIZE並沒有考慮到,我必須重新執行它!

不過說真的,大家好,感謝您的回答:)