// Wait for PhoneGap to load
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
function onDeviceReady() {
// Do cool things here...
}
function getImage() {
// Retrieve image file location from specified source
navigator.camera.getPicture(uploadPhoto, function(message) {
alert('get picture failed');
},{
quality: 100,
destinationType: navigator.camera.DestinationType.FILE_URI,allowEdit: true,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
}
);
}
function uploadPhoto(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 = {
email : localStorage.getItem('email')
}
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "http://localhost/app/photo.php", win, fail, options);
}
function win() {
location.href="settings.html";
}
function fail(error) {
alert("Erro ao enviar foto!");
}
</script>
Apparently it works without problems. However, I'm using the php code below to check whether the file exists or not, so if it exists it will put the photo otherwise it puts a default image:
$setphoto = "http://localhost/app/_profile_photo/$userid.jpg";
$photodefault = "http://localhost/app/_profile_photo/default-image.png";
if (file_exists($setphoto)){
echo "<img src=\"$setphoto\" width=\"80\" height=\"80\">";
}
else{
echo "<img src=\"$photodefault\" width=\"80\" height=\"80\">";
}
The problem is that the file_exists () function is not recognizing the uploaded file and always takes the default photo.
What I've tested:
1- Check if the $ userid is correct in the path of the photo. 2- I used the function as! File_exists () and it shows the right image. 3- Right-click on the html image src="http://localhost/app/_profile_photo/aquiOIdDoUsuario.jpg" > - Show the image.
I need to know how to make the file_exists () function verify that the file is.
Thank you.