This article provides a detailed analysis of the two solutions to restrict the size of uploaded files in php before uploading. For more information, see
This article provides a detailed analysis of the two solutions to restrict the size of uploaded files in php before uploading. For more information, see
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 this variable, the file has been uploaded and saved in the temp directory. If you try to reject File Upload because of disk capacity or bandwidth, the large file is actually uploaded (although they are deleted immediately ), this may be a problem for you.
A better way is to tell php in advance the maximum size of the file you want to accept.
There are two methods.
The first one is to adjust the upload_max_filesize settings in your php. ini file. The default value is 2 mb, so if you want to accept a larger file, you need to change the value immediately.
The second method is to include an implicit input field in your form. Its name is max_file_size, in which you can define the maximum file size you can accept. For security reasons, this value cannot exceed your php. the setting of upload_max_filesize In the INI file, but it provides a way to define the maximum size of uploaded files on different pages. For example, for a Hong Kong server lease, the following form, the Hong Kong virtual host, only allows us to upload up to 1 kb of files (1024 bytes ):
The Code is as follows: