Sie sind auf Seite 1von 2

/*$(document).

ready(function() {
console.log("pic upload.js loaded");
});*/
var img_path_new = null;

function capture() {

navigator.camera.getPicture(onSuccess, onFail, {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
correctOrientation: true,
});

function onSuccess(imageURI) {
var image = document.getElementById('fetched_img');
image.style.display = 'block';
image.src = imageURI;
// window.plugins.toast.show(imageURI, 'long', 'center');
console.log("Image Saved at ===> " + imageURI);
// $("#image_url").text(imageURI);

var source_url = imageURI;


var absolutepath = cordova.file.externalRootDirectory + '.Student_Buddie';
console.log(absolutepath);

var thisday = new Date();


var date = thisday.getFullYear() + '_' + (thisday.getMonth() + 1) + '_' +
thisday.getDate();
var time = thisday.getHours() + '_' + thisday.getMinutes() + '_' +
thisday.getSeconds();
var stamp = date + '_' + time;

console.log(stamp);
//new file name
var ImageName = stamp + ".jpg";
console.log(ImageName);

var fail = function(err) {


console.log(err)
}

window.resolveLocalFileSystemURL(source_url, function(file) {
window.resolveLocalFileSystemURL(absolutepath, function(destination) {
file.moveTo(destination, ImageName);
}, fail)
}, fail);

console.log("file Successfully moved to =>" + absolutepath + '/' +


ImageName);
alert("file Successfully moved to =>" + absolutepath + '/' + ImageName);
img_path_new = absolutepath + '/' + ImageName;
// $("#path").text("file moved to =>"+img_path_new);

//document.getElementById("fetched_img").setAttribute("src",img_path_new);
window.setTimeout(
function() {
$("#fetched_img").attr('src', img_path_new);
}, 2000);
}

function onFail(message) {
console.log('Failed because: ' + message);
}

function upload_pic_remote() {
var id_user = localStorage.getItem("vone_ls");
console.log(id_user + "in pic_upload.js");
console.log(img_path_new + "in pic_upload.js");

var pic_path = img_path_new;

$.support.cors = true;
$.ajax({
type: "POST",
url: "https://florid-pumps.000webhostapp.com/upload_pic.php", // Example
data: {
pic_path: pic_path,
id: id_user,
},
cache: false,
success: function(response) {
var responseData = jQuery.parseJSON(response);
console.log(responseData);
console.log(responseData.status);
//navigator.notification.alert("responseData.status");
alert("profile Pic Successfully Updated");
},
error: function(e) {
alert('Error: ' + e.message);
}
});
alert("profile Pic uploaded Successfully!!");
}

Das könnte Ihnen auch gefallen