2016-08-22 3 views
0

EDIT: Changed win() -Funktion und hinzugefügt am Bild entspricht seinem Ergebnis.Probleme mit dem Hochladen von Bild auf den Webserver mit Phonegap

Ich habe Probleme beim Hochladen von Bild auf einen Webserver mit Phonegap.

Dies ist der Code, den ich für die app:

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

Der Code löst win() Funktion und zeigt die JSON Daten des Ergebnisses, wenn das Bild so zumindest erfasst wird es nicht ausfällt().

Und hier ist ein Bild von was win() - Funktion Warnungen.

win() function alert message

und das ist, was meine upload.php wie folgt aussieht:

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

Haben Sie die entsprechenden Berechtigungen (lesen, schreiben) in Ihrem 'uploads /' Ordner? –

+0

Silly mich, danke eine Tonne! –

+0

Cool !. Ich habe das als Antwort unten gepostet. Kannst du es bitte akzeptieren? –

Antwort

1

Stellen Sie sicher, dass Sie alle entsprechenden haben (Lesen/Schreiben) Berechtigungen auf Ihre Zielordner uploads/, wo Sie versuchen, Lade deine Dateien hoch.

Hoffe, das hilft !.