Home > Backend Development > PHP Tutorial > Configuration method to limit file size before uploading in php

Configuration method to limit file size before uploading in php

WBOY
Release: 2016-07-25 08:58:25
Original
1088 people have browsed it
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:

select file to upload:



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template