Hello! I have a simple code to upload a file to server. <!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action="upload3.php" enctype="multipart/form-data" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="2097152" /> Upload File: <input name="file_upload" type="file" /> <input type="submit" value="Enviar fichero" /> </form> </body> </html> HTML: In PHP: <?php define('APP_BASEDIR', dirname(__FILE__)); $ruta = APP_BASEDIR . "/cargas/"; $file_uploaded = $ruta. basename($_FILES['file_upload']['name']); if (move_uploaded_file($_FILES['file_upload']['tmp_name'], $file_uploaded)) { echo "OK"; } else { echo "ERROR!"; } ?> PHP: If the file is small, there is no problem. But if the file is very large, it fails. Show this: And tell Notice: Undefined index... this because $_FILE are empty (see http://php.net/manual/en/ini.core.php#ini.post-max-size) I don't need to upload a large file. I just want to validate on the server side that a large file is not loaded (2Mb Max). Can someone help me?
You can use the error code to validate the file. For more information and examples check: http://php.net/manual/en/features.file-upload.errors.php http://php.net/manual/en/features.file-upload.php
Its a variable in php.ini which is making the script fail. Increase its limit and script will continue as normal. ; Maximum size of POST data that PHP will accept. post_max_size = 8M Make this: post_max_size = 18M or post_max_size = 25M or so on... Whatever is needed...
This one also needs to be increased. ; Maximum allowed size for uploaded files. upload_max_filesize = 2M