Iam이 PHP 백엔드가 포함 된 웹 서버에 사진을 업로드 할 수 없습니다. 내 코도 바 카메라 스크립트는 사진을 찍을 수 있고 작은 크기로 사진을 보여줄 수 있습니다. 하지만 이미지를 업로드 할 수는 없습니다. 나는 이유가 없다. 나는 함수 photoUpload()를 호출한다. 단추의 onClick 이벤트를 설정하십시오.파일 업로드 버튼이 여전히 Cordova/Phonegap Project에서 작동하지 않습니다.
<button class="camera-control" onclick="photoUpload();">UPLOAD</button>
여기 내 JavaScript는 무엇입니까?
var pictureSource;
var destinationType;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}
function clearCache() {
navigator.camera.cleanup();
}
var retries = 0;
function onCapturePhoto(fileURI) {
$("#cameraPic").attr("src", fileURI);
var win = function (r) {
clearCache();
retries = 0;
navigator.notification.alert(
'',
onCapturePhoto,
'Der Upload wurde abgeschlossen',
'OK');
console.log(r);
}
var fail = function (error) {
navigator.notification.alert(
'Bitte versuchen Sie es noch einmal.',
onCapturePhoto,
'Ein unerwarteter Fehler ist aufgetreten',
'OK');
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
if (retries == 0) {
retries ++
setTimeout(function() {
onCapturePhoto(fileURI)
}, 1000)
} else {
retries = 0;
clearCache();
alert('Fehler!');
}
}
function photoUpload() {
var fileURI = $("#cameraPic").attr("src");
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
options.chunkedMode = false;
var params = new Object();
params.fileKey = "file";
options.params = {}; // eig = params, if we need to send parameters to the server request
var ft = new FileTransfer();
ft.upload(fileURI, encodeURI("http://xxxx/app/upload.php"), win, fail, options);
}
}
function capturePhoto() {
navigator.camera.getPicture(onCapturePhoto, onFail, {
quality: 50,
destinationType: destinationType.FILE_URI
});
}
function getPhoto(source) {
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
function onFail(message) {
alert('Failed because: ' + message);
}
당신이 그것을 디버깅하려고 했습니까? 기능 업로드 사진 안에 있다면? – Simcha
방화범이 들었습니다 : ReferenceError : photoUpload가 정의되지 않았습니다. – fcb1900
js 파일이 서버에서로드되고 있는지 확인하십시오.이 파일은 기본적으로 서버가 아닌 js 파일이고 기본 * .html 파일은 서버가 아닙니다. 반환. – Simcha