SOLVED THE PROBLEM.
The problem is already solved and I explain it to you next in case someone else happens the same.
The code initially worked without any problem but when uploading the images some of them failed and were uploaded in a corrupted way or upload to the server.
After trying a thousand ways to upload the files I found the fault and it was not in the code but in the configuration of xampp / wampp. These default programs have a memory limit configured to use in the forms that is usually quite low in my case it was 2M what I did is increase it to 12GB and problem solved !!
The steps I followed are the following: (with xampp)
Edit with the notepad or another editor and look for the following lines of code:
memory_limit (al ser un server dedicado le puse el 80% de la RAM disponible.)
upload_max (estaba en 2M y lo puse en 12000M unos 11GB)
post_max_size(estaba en 2M y lo puse en 12000M unos 11GB)
The first parameter is the total php limit to work in memory, so it always has to be equal to or greater than the other two, the second is the maximum memory that it uses when uploading files (which is where it resided) my problem) and the third field is to send the complete form with the POST method.
I hope it will help you because it is a very common problem and I have not found anything related in forums on how to solve it, luck to others!
## ERROR UPLOAD IMAGES HAVING THE CODE OK, BOTH THE BBDD AND THE SERVER ##
I've been facing a curious error for a few weeks that I can not see solved in any Internet forum.
I have a website where images are uploaded through a fairly simple code and a simple form, most images are uploaded without any problem and without any incidence. But there are certain images (I can not see that they have in common) that fail at the time of uploading to the server.
I have tried everything that has occurred to me I have tried to store them both in the DB and move them to a folder in the server but the error persists with those images and I can not find out why it is ... I leave the code of the. php
<?php
SESSION_START();
error_reporting(-1);
$nom = $_SESSION['nombreusuario'];
$conexion= mysqli_connect("localhost","root","","elarbusto");
$caracteres='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$longpalabra=8;
for($pass123='', $n=strlen($caracteres)-1; strlen($pass123) < $longpalabra ; ) {
$x = rand(0,$n);
$pass123.= $caracteres[$x];
}
$ruta="./ImagenesWEB/AvatarPerfil/";//ruta carpeta donde queremos copiar las imágenes
$uploadfile_temporal=$_FILES['Logo']['tmp_name'];
$uploadfile_nombre=$ruta.$_FILES['Logo']['name'];
$extension = ".".end(explode(".", $_FILES['Logo']['name']));
$nombre = $nom.date('Y-m-d').$pass123.$extension;
$nombreComp = $ruta.$nombre;
if (is_uploaded_file($uploadfile_temporal))
{
move_uploaded_file($uploadfile_temporal,$nombreComp);
$modusuarioLider = "UPDATE 'usuarios' SET 'Avatar' = '.$nombreComp' WHERE 'Nick' = '$nom' ";
$realizarmod = mysqli_query($conexion, $modusuarioLider);
header("location:cuerpoweb/INDPerfil.php");
}
else
{
header("location:cuerpoweb/INDPerfil.php?error=4");
}
mysqli_close($conexion);
?>
If someone sent from heaven is able to help me, I would be grateful enough!
ADDED CONTENT TO CLARIFY MORE THEME:
At the request of friend Oscar I upload a simpler version of the code, both an HTML and a php:
upload picture folder.html: Untitled document
<body>
<form action="subirimagencarpeta2.php" method="post" enctype="multipart/form-data">
Archivo: <input name="fichero" type="file">
<input name="submit" type="submit" value="Upload!">
</form>
</body>
</html>
upload picture folder2.php:
<?php
$ruta="./pruebaimagenes/";//ruta carpeta donde queremos copiar las imágenes
$uploadfile_temporal=$_FILES['fichero']['tmp_name'];
$uploadfile_nombre=$ruta.$_FILES['fichero']['name'];
$extension = ".".end(explode(".", $_FILES['fichero']['name']));
if (is_uploaded_file($uploadfile_temporal))
{
move_uploaded_file($uploadfile_temporal,$ruta.'ejemplonombre'.$extension);
}
else
{
echo "error";
}
?>
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php echo "<img src=".$ruta.'ejemplonombre'.$extension.">"; ?>
</body>
</html>
I think if you let me attach images, here is one that does not allow upload and another that does. (do not let me upload the images by size, I'll leave them in a link)
Image that does not allow upload: link
Image that allows upload: link