Olá, eu estou utilizando o seguinte código para fazer upload da imagem de um app phonegap para um servidor :
// 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>
Aparentemente funciona sem problemas. Porém, eu estou usando o código php abaixo para verificar se o arquivo existe ou não, assim, se existir ele vai colocar a foto caso contrario ele coloca uma imagem padrão:
$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\">";
}
O problema é que a função file_exists() não está reconhecendo o arquivo enviado e sempre pega a foto padrão.
O que eu já testei:
1- Verifiquei se o $userid esta correto no caminho da foto. 2- Usei a funcão como !file_exists() e ele passa a mostrar a imagem certo. 3- Colocar direto no html a imagem src="http://localhost/app/_profile_photo/aquiOIdDoUsuario.jpg"> - Mostra a imagem.
Eu preciso saber como fazer para a função file_exists() verificar que o arquivo está la.
Obrigado.