I have a problem uploading images to the server from a mobile device. When I run my web application from the computer everything works correctly, the images go up without problems. But when I do it from a cell phone, I do not load the images that are selected. I pass the code to you so please help me.
This code is not the one I want to solve directly, but it is practically the same with fewer validations, but neither does the image upload when I open the page from the cell phone (With S.O Android).
HTML
<!DOCTYPE html>
<html>
<head>
<title>formulario</title>
<script src="jquery.js"></script>
<script src="crud.js"></script>
</head>
<body>
<form id="formulario" >
<input type="file" name="imagen" id="imagen">
<button type="submit" id="btnenviar">Enviar</button>
</form>
</body>
</html>
JQUERY
$(document).ready(function(){
$("body").on("click","#btnenviar", function(e){
e.preventDefault();
var formData = new FormData(document.getElementById("formulario"));
$.ajax({
type: "POST",
url: "servidor/upimage.php",
data: formData,
processData: false,
contentType: false,
success: function (respuesta){
alert(respuesta);
}
});
});
});
PHP
<?php
if ($_FILES["imagen"]['error']==0) {
if ($_FILES["imagen"]['type']=="image/png" || $_FILES["imagen"]['type']=="image/jpg" || $_FILES["imagen"]['type']=="image/jpeg") {
$target_path = "../";
$target_path = $target_path . basename( $_FILES['imagen']['name']);
if(move_uploaded_file($_FILES['imagen']['tmp_name'], $target_path))
{
echo "El archivo ". basename( $_FILES['imagen']['name']). " ha sido subido";
} else{
echo "Ha ocurrido un error con el archivo ". basename( $_FILES['imagen']['name']) ;
}
}else{echo $_FILES["imagen"]['type']." Solo se pueden subir archivos tipo JPG, PNG Y JPEG.";}
}else{
echo "Por favor seleccione un archivo para subir";
}
?>