Home > Backend Development > PHP Tutorial > Two solutions in PHP to limit the size of uploaded files before uploading_PHP Tutorial

Two solutions in PHP to limit the size of uploaded files before uploading_PHP Tutorial

WBOY
Release: 2016-07-21 15:03:58
Original
822 people have browsed it

Although you can use a similar technique to reject files that are too large (by checking the $uploadedfile_size variable), this is generally not a good idea. Before getting this variable, this file has been uploaded and saved in the temp directory. This may be a problem for you if you try to reject a file upload due to disk capacity or bandwidth reasons, and the large files are actually uploaded anyway (even though they are immediately deleted).

A better way is that you can tell PHP in advance the upper limit of the file size you want to accept.
There are two methods.
The first is to adjust the upload_max_filesize setting in your php.ini file.
The default value is 2mb, so if you want to accept larger files, you need to change this 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 largest 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 upper limit of upload file size in different pages. For example, the following form only allows us to upload files up to 1k bytes (1024 bytes):

Copy code The code is as follows:

enctype="multipart/form-data">

select file to upload:






www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327813.htmlTechArticleWhile you can use a similar technique to reject overly large files (by checking the $uploadedfile_size variable), usually This is not a good idea. Before getting this variable, this text...
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