Php file size limit configuration method before uploading
| This article introduces how to restrict the file size before uploading a file in php. For more information, see.
In php programming, when it comes to file upload, you are always used to checking the $ uploadedfile_size variable. this is a disadvantage. Before getting this variable, the file has been uploaded and saved in the temp directory. If you refuse to upload a file because of disk capacity or bandwidth, the large file is uploaded. The next step is to delete it.
This article introduces how to restrict the upload of files to a specific range in advance. if this limit is exceeded, no content will be uploaded?
Here we will introduce two methods.
Method 1: adjust the upload_max_filesize setting in the php. ini file. The default value is 2 mb.
Method 2: The form contains an implicit input field named max_file_size, which defines the maximum file size you can accept. Based on security considerations, this value cannot exceed the setting of upload_max_filesize in the php. ini file. However, it provides a way to define the maximum size of uploaded files on different pages. For example, in the following commendation, only 1 K bytes of files (1024 bytes) can be uploaded ): Sample code: |