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.
This code is not directly the one I want to solve, but it is practically the same with fewer validations, but still, the image does not go up when I open the page from the cell phone (With S.O Android).
$(document).ready(function(){
$('form[name="frmname[]"]').on("submit", function(e){
e.preventDefault();
var nombre = $("#filename").val();
if (nombre =! "") {
$.ajax({
type: 'POST',
url: 'enlace.php',
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
success: function(data) {
alert(data);
},
fail: function(error){
alert(error);
}
});
}
});
});
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="icon" href="http://i0.wp.com/www.hidromasa.com/wp-content/uploads/2016/08/icono-gota-agua-Hidromasa.png?fit=512%2C512" type="image/ico" />
<title></title>
</head>
<!-- Bootstrap -->
<link href="assets/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<body>
<div class="container">
<div class="row">
<form name="frmname[]" enctype="multipart/form-data">
<div class="form-group ">
<label>Nombre:</label>
<input type="text" id="filename[]" name="frmname" required="required">
</div>
<div class="form-group ">
<label>Subir archivo:</label>
<input type="file" id="file" name="file" multiple>
</div>
<button type="submit" class="btn btn-primary">Guardar</button>
</form>
</div>
</div>
<!-- jQuery -->
<script src="assets/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="assets/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- JS -->
<script src="assets/js/main.js"></script>
</body>
</html>
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";
}
?>