This article introduces how to limit the size of the file before uploading it in PHP. Friends in need can refer to it.
In PHP programming, when it comes to uploading files, it is always customary to check the $uploadedfile_size variable, which has shortcomings. It will get this variable before the file has been uploaded and saved in the temp directory. If the file upload is rejected due to disk capacity or bandwidth reasons, in fact, the large file is still uploaded, and the next thing to do is to delete it. This article introduces how to limit uploaded files to a range in advance, and no content will be uploaded beyond this limit? Here are two methods. Method 1, adjust the upload_max_filesize setting in the php.ini file. The default value is 2mb. Method 2, include an implicit input field in the 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 the upload_max_filesize setting in the php.ini file. However, it provides a way to define the upper limit of upload file size individually in different pages. For example, in the following commendation, only files up to 1k bytes (1024 bytes) are allowed to be uploaded: Copy code Code example: |