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.
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);
?>
Haben Sie die entsprechenden Berechtigungen (lesen, schreiben) in Ihrem 'uploads /' Ordner? –
Silly mich, danke eine Tonne! –
Cool !. Ich habe das als Antwort unten gepostet. Kannst du es bitte akzeptieren? –