2016-08-22 3 views
0

편집 : 변경된 win() 함수가 변경되어 그 결과에 해당하는 이미지가 추가되었습니다.phonegap을 사용하여 웹 서버에 이미지를 업로드 할 때의 문제

phonegap을 사용하여 웹 서버에 이미지를 업로드하는 데 문제가 있습니다.

내가 앱이 코드입니다 :

var pictureSource; // picture source 
var destinationType; // sets the format of returned value 

// Wait for Cordova to connect with the device 
// 
document.addEventListener("deviceready",onDeviceReady,false); 

// Cordova is ready to be used! 
// 
function onDeviceReady() { 
    pictureSource=navigator.camera.PictureSourceType; 
    destinationType=navigator.camera.DestinationType; 
} 

// Called when a photo is successfully retrieved 
// 
function onPhotoURISuccess(imageURI) { 

    // Get image handle 
    // 
    var largeImage = document.getElementById('largeImage'); 

    // Unhide image elements 
    // 
    largeImage.style.display = 'block'; 

    // Show the captured photo 
    // The inline CSS rules are used to resize the image 
    // 
    largeImage.src = 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://www.tayabsoomro.me/upload.php", win, fail, options); 
} 

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

function fail(error){ 
    alert("An error occured while uploading image: " + error.code); 
} 

코드는 승리() 함수를 트리거하고 이미지가 적어도 실패하지 않도록 캡처 될 때 결과의 JSON 데이터를 보여줍니다().

다음은 win() 함수 알림의 이미지입니다.

win() function alert message

이 내 upload.php로의 모습입니다 : 당신은 당신이 시도 할 대상 폴더 uploads/에 설정된 모든 적절한 (읽기/쓰기) 권한이 있는지 확인

<?php 
print_r($_FILES); 
$new_image_name = "myimg.jpg"; 
move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/".$new_image_name); 
?> 
+1

'uploads /'폴더에 적절한 권한 (읽기, 쓰기)이 설정되어 있습니까? –

+0

어리석은 나를, 당신에게 1 톤 감사하십시오! –

+0

차가운!. 나는 그 대답을 아래에 게시했다. 수락 해 주시겠습니까? –

답변

1

파일을 업로드하십시오.

희망이 도움이됩니다!.

관련 문제