In php, there are two solutions to limit the size of the uploaded file before upload.

Source: Internet
Author: User

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 the upload_max_filesize setting in your php. ini file, but it provides a way to define the maximum size of uploaded files on different pages. For example, the following form only allows us to upload files up to 1 kb (1024 bytes ):Copy codeThe Code is as follows: <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>

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: 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.