2013-07-30 2 views
1

this PhoneGap 예를 들어 장치에서 서버로 이미지를 업로드하는 중입니다. 위에서 언급 한 예와는 달리, 나는 데이터베이스에 데이터를 게시하지만, 보안 URL을 사용하여 HTML을 통해 직접 게시 할 수 PHP 파일을 사용하고 있지 않다 나의 경우PhoneGap Ajax 업로드 파일

// Wait for PhoneGap to load 
    // 
    document.addEventListener("deviceready", onDeviceReady, false); 

    // PhoneGap is ready 
    // 
    function onDeviceReady() { 

     // 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 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; 

     var ft = new FileTransfer(); 
     ft.upload(imageURI, "http://some.server.com/upload.php", win, fail, options); 
    } 

    function win(r) { 
     alert("Code = " + r.responseCode); 
     alert("Response = " + r.response); 
     console.log("Sent = " + r.bytesSent); 
    } 

    function fail(error) { 
     alert("An error has occurred: Code = " + error.code); 
     alert("upload error source " + error.source); 
     alert("upload error target " + error.target); 
    } 

. 그런 데스크톱 버전에 보이는 것 뭔가 :

<form action="https://mySecureUrl.com/?filename=myImage" method="post" enctype="multipart/form-data"> 
<input type="file" name="myfile"><br> 
<input type="submit" value="Upload File to Server"> 
</form> 

지금은 폰갭 FileTransfer를 (사용하여 동일한 방법을 적용하려고)와 나는 3

var ft = new FileTransfer(); 
ft.upload(imageURI, encodeURI("https://mySecureUrl.com/?filename=myImage.jpg"), win, fail, options); 
  • 인가 에러 코드를 얻을 이 방법으로 PhoneGap에 파일을 게시 할 수 있습니까? 방법?
  • 그렇지 않다면 PHP 솔루션은 무엇입니까?
+0

당신이 사용하는 폰갭 버전은 무엇? 당신은 1.5의 예제에 링크하고 있지만 그 이후로 메소드는 http://docs.phonegap.com/en/3.0.0/cordova_file_file.md.html#FileTransfer –

+0

으로 변경되었습니다. 고마워요. 나는 함수명을 바꾸었지만 여전히 운이 없다. 'chunkedMode = false'를 설정하면 파일을 찾을 수 없으며 오류 및 http status = 500을 얻을 수 있습니다. 나는 정말로 여기에서 길을 잃는다. 서버 로그에 \ r \ n 문자로 인한 업로드 실패가 표시됩니다. 아이디어가 있습니까? – grmmph

+0

불법 문자가 어디에 있다고 말할까요? 또한 fileKey를 확인하십시오. 양식의 이름과 코드의 키가 다릅니다. –

답변

0

options 아래의 fileKey는 서버가 찾을 이름입니다. HTML에서 "myfile"로 설정된 이름이 있고 javascript에는 "file"이 있습니다.

<input type="file" name="myfile"> 

options.fileKey="file"; 

options.fileKey 및 속성 이름이 같은 것을, 그래서 당신의 PHP는 "파일"에 대한 $ _FILES 배열에보고되어 있는지 확인

+0

입니다. – grmmph

+0

서버 로그에 불법적 인 헌장이 있다고합니다. – grmmph