The form to upload a file using PHP is this:
<form action="subir_file.php" enctype="multipart/form-data" method="POST">
<!-- MAX_FILE_SIZE debe preceder al campo de entrada del fichero -->
<input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
<!-- El nombre del elemento de entrada determina el nombre en el array $_FILES -->
Enviar este fichero: <input name="file" type="file" />
<input type="submit" name="upload" value="Subir">
<input type="submit" name="cerrar" value="Cerrar">
</form>
In the PHP file I have:
ini_set('error_reporting', NULL); // Lo agregué para evitar el mensaje de WARNING, pero igual se muestra....
if(!isset($_FILES['file']['tmp_name'])) {
echo "VACIO";
exit;
}
echo "<pre>";
print_r($_FILES); //Cuando el archivo es muy grande no muestra nada.
I am testing receiving the working file which is normally less than 1MB. I want to restrict an extremely large file from being uploaded and on the server side allow me to validate this to display a "File Too Large" message. But doing so throws me this message and the array contains nothing:
Warning: POST Content-Length of 191932818 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
Array
(
)
But if the array arrives empty I should be able to display my custom message, but the Warning: POST Content-Lenght...
. And that shouldn't happen. And to not show the Warning I added this:
ini_set('error_reporting', NULL);
either
ini_set('error_reporting', 0);
either
error_reporting(0);
And neither works. Keep showing the Warning
.
Try like this:
This code is to validate on the client side that they cannot upload more than 2MB, in this way you avoid the server having to validate the size and type of file.