2014-11-30 2 views
0

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); 
} 
+0

당신이 그것을 디버깅하려고 했습니까? 기능 업로드 사진 안에 있다면? – Simcha

+0

방화범이 들었습니다 : ReferenceError : photoUpload가 정의되지 않았습니다. fcb1900

+0

js 파일이 서버에서로드되고 있는지 확인하십시오.이 파일은 기본적으로 서버가 아닌 js 파일이고 기본 * .html 파일은 서버가 아닙니다. 반환. – Simcha

답변

0

기능 사진을보세요. 업로드 기능은 사진 캡처 기능에 있습니다! 당신은 최상위 수준에서 기능을 사진 업로드를 이동해야합니다.

window.photoUpload = function() { 
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); 
} 

그리고 더 좋은 방법은 그것을 좋아합니까합니다 :

<button class="camera-control" id="photoUploadButton;">UPLOAD</button> 

document.getElementById("photoUploadButton").addEventListener("click", photoUpload); 
+0

이렇게하면 업로드 버튼에는 아무런 기능이 없습니다. – fcb1900

+0

확인한 후 다음을 시도하십시오 (업데이트 된 답변 참조). – Simcha

관련 문제