Php file size limit configuration method before uploading

Source: Internet
Author: User
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.