Two solutions in php that limit the size of uploaded files before they are uploaded

  • 2020-06-19 09:54:48
  • OfStack

Although you can use a similar technique to reject large files (by checking the $uploadedfile_size variable), this is usually not a good idea. Before getting the variable, the file is uploaded and saved in the temp directory. If you try to deny the upload of a file because of disk capacity or bandwidth, the fact that the large file was actually uploaded (even though it was deleted immediately) may be a problem for you.

Better yet, you can tell php ahead of time the maximum size of the file you want to accept.
There are two ways.
The first is to adjust the upload_max_filesize Settings in your ES8en.ini file. The default value is 2mb, so if you want to accept larger files, you need to change this value immediately.

The second method is to include an implicit input field in your form, called max_file_size, where you can define the maximum file size you can accept. For security reasons, this value cannot exceed the upload_max_filesize setting in your ES20en.ini file, but it provides a way to define the upper limit of the upload file size on different pages. For example, the following form allows us to upload only files with a maximum of 1k bytes (1024 bytes) :

<form action="fileupload.php" method=post 
enctype="multipart/form-data"> 
<p>select file to upload: 
<input type=file name="uploadedfile"></p> 
<p><input type=submit name="submit" value="submit"></p> 
<input type=hidden name=max_file_size value=1024> 
</form> 


Related articles: