Skip to content
PHP Logo

What is the significance of the MAX_FILE_SIZE attribute in HTML forms for file uploads?

The MAX_FILE_SIZE attribute in HTML forms is used to limit the size of files that can be uploaded through the form. This attribute is important because it helps prevent users from uploading excessively large files that could potentially overwhelm the server or cause other issues. By setting a maximum file size, you can ensure that only files within a certain size limit are accepted for upload.

php
<form action="upload.php" method="post" enctype="multipart/form-data">
  <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <!-- Limit file size to 1MB -->
  <input type="file" name="fileToUpload" />
  <input type="submit" value="Upload File" />
</form>