Вы не можете получить доступ к камере с PHP.
, но вы можете отправить изображение на php бэкэнд, используя ajax плагин запроса и файла кордовы
cordova plugin add cordova-plugin-file-transfer
Php файл на сервере
<?php
// Set new file name
$new_image_name = "newimage_".mt_rand().".jpg";
// upload file
move_uploaded_file($_FILES["file"]["tmp_name"], 'upload/'.$new_image_name);
echo $new_image_name ;
HTML файл на телефоне
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'" />
<title>PhoneGap app</title>
<!-- Script -->
<script type="text/javascript" src="cordova.js" ></script>
<script type='text/javascript' src='jquery-3.0.0.js' ></script>
<script type='text/javascript'>
$(document).ready(function(){
// take picture from camera
$('#but_take').click(function(){
navigator.camera.getPicture(onSuccess, onFail, { quality: 20,
destinationType: Camera.DestinationType.FILE_URL
});
});
// upload select
$("#but_select").click(function(){
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: true,
destinationType: Camera.DestinationType.FILE_URI
});
});
// Change image source and upload photo to server
function onSuccess(imageURI) {
// Set image source
var image = document.getElementById('img');
image.src = imageURI + '?' + Math.random();
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
var params = {};
params.value1 = "test";
params.value2 = "param";
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "https://example.com/upload.php", function(result){
alert('successfully uploaded ' + result.response);
}, function(error){
alert('error : ' + JSON.stringify(error));
}, options);
}
function onFail(message) {
alert('Failed because: ' + message);
}
});
</script>
</head>
<body>
<img src="img/test.jpg" id='img' style="width: 100px; height: 100px;">
<br/>
<button id='but_take'>Take photo</button>
<button id='but_select'>Select photo from Gallery</button>
</body>
</html>