Untitled diff
51 lines
var imgURI;
var imgURI;
var serverURL ="ajlnfioej/upload.php";
var serverURL ="ajlnfioej/upload.php";
$(document).ready(function(){
$(document).ready(function(){
document.addEventListener('deviceready', getCameraReady, false);
document.addEventListener('deviceready', getCameraReady, false);
});
});
function getCameraReady(){
function getCameraReady(){
$('#btCamera').on('click', function(e){
$('#btCamera').on('click', function(e){
options = {quality:50, destinationType: Camera.Destination.FILE_URI, sourceType: pictureSource.CAMERA};
var options = {quality:50, destinationType: Camera.DestinationType.FILE_URI, sourceType: Camera.PictureSourceType.CAMERA};
navigator.camera.getPicture(photoSuccess, photoFail,[options]);
navigator.camera.getPicture(photoSuccess, photoFail, options);
});
});
$('#btPhotoLib').on('click', function(e){
$('#btPhotoLib').on('click', function(e){
options = {quality:50, destinationType: Camera.Destination.FILE_URI, sourceType: pictureSource.PHOTOLIBRARY};
var options = {quality:50, destinationType: Camera.DestinationType.FILE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY};
navigator.camera.getPicture(photoSuccess, photoFail,[options]);
navigator.camera.getPicture(photoSuccess, photoFail, options);
});
});
$('#btUpload').on('click', function(e){
$('#btUpload').on('click', function(e){
var options = new FileUploadOptions();
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileKey = "file";
options.fileName = imgURI.substr(imgURI.lastIndexOf('/')+1);
options.fileName = imgURI.substr(imgURI.lastIndexOf('/')+1);
options.mimeType = "image/jpeg";
options.mimeType = "image/jpeg";
var ft = new FileTransfer();
var ft = new FileTransfer();
var server = encodeURI(serverURL);
var server = encodeURI(serverURL);
ft.upload(imgURI, server,uploadSuccess, uploadFail,options);
ft.upload(imgURI, server,uploadSuccess, uploadFail,options);
});
});
}
}
function photoSuccess(uri){
function photoSuccess(uri){
$("#img").attr("src", uri);
$("#img").attr("src", uri);
$("#img").css("width": "100%", "height": "100%");
$("#img").css({"width": "100%", "height": "100%"});
imgURI = uri;
imgURI = uri;
}
}
function cameraError(message){
function cameraError(message){
navigator.notification.alert("camera usage not supported on this device");
navigator.notification.alert("camera usage not supported on this device");
}
}
function uploadSuccess(result){
function uploadSuccess(result){
navigator.camera.cleanup();
navigator.camera.cleanup();
navigator.notification.alert("Number of bytes is : " + results.bytesSent);
navigator.notification.alert("Number of bytes is : " + result.bytesSent);
navigator.notification.alert("Http Response is : " +results.response );
navigator.notification.alert("Http Response is : " +result.response );
}
function uploadFail(error){
alert("Am error has occured: Code = " + error.code);
}
function uploadFail(){
function photoFail(error){
alert("Am error has occured: Code = " + error.code);
alert("Am error has occured: Code = " + error.code);
}
}