我现在正在制作一个混合应用程序。 然后,实现在设备库中上传图像并不顺利。
使用通用FTP进行上传,错误消除了PHP端。
[剧本来源]
var pictureSource;
var destinationType;
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function onPhotoDataSuccess(imageData) {
var smallImage = document.getElementById('smallImage');
smallImage.style.display = 'block';
smallImage.src = "data:image/jpeg;base64," + imageData;
}
function onPhotoURISuccess(imageURI) {
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
}
function capturePhoto() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 90,
correctOrientation : true,
saveToPhotoAlbum : true,
destinationType: destinationType.DATA_URL });
}
function capturePhotoEdit() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 90,
allowEdit: true,
correctOrientation : true,
saveToPhotoAlbum : true,
destinationType: destinationType.DATA_URL });
}
function getPhoto(source) {
// navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 90,
navigator.camera.getPicture(uploadPhoto, onFail, { quality: 90,
correctOrientation : true,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
function onFail(message) {
alert('Failed because: ' + message);
}
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.chunkedMode = false;
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;
var fileTransfer = new FileTransfer();
fileTransfer.upload(
imageURI,
"http://192.168.0.26/android/upload.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");
}
function fail(error){
alert("error :Code = " + error.code);
}

[PHP来源]
<?php
print_r($_FILES);
move_uploaded_file($_FILES["file"]["tmp_name"], 'C:/Users/MyPC/Desktop/');
?>
&#13;
当它使用路径的原因时,希望保存在桌面中。 如果在图库中选择了照片并且实施了上传,则会出现一个无法形成的错误,并且不会发生某些错误。
明确将类型放入选项并发送。 但Type值为空白值。
只有文件名(=图像URI)似乎正确传递。
如果与PHP端问题相同,你如何修复,因为我看到了?
供您参考,upload.php的路径是&#34; C:\ Apache24 \ htdocs \ android&#34;。
我希望能解决这个问题。感谢。