【发布时间】:2014-04-09 20:09:28
【问题描述】:
我发现,如果您在服务器上使用带有 php 的 phonegap 上传图像,它每隔一段时间就会起作用。始终如一。第一个upolad成功,第二个失败,第三个成功,第四个失败,依此类推。
我正在使用位于此处的示例: How to retrieve POST data from PhoneGaps File Transfer API
我正在使用安卓手机进行测试。
// Wait for PhoneGap to load
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
function onDeviceReady() {
console.log("device ready");
// Do cool things here...
}
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 captureImage() {
// 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
});
}
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();
params.value1 = "test";
params.value2 = "param";
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "http://someserver.com/somedir/up.php", win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode.toString() + "\n");
console.log("Response = " + r.response.toString() + "\n");
console.log("Sent = " + r.bytesSent.toString() + "\n");
alert("Code Slayer!!!");
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
}
还有php
<?php
print_r($_FILES);
$new_image_name = "YEAH.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "../uploads/".$new_image_name);
?>
【问题讨论】:
-
请发布您的代码。