How to set size limit for file upload using php

不言
Release: 2023-04-05 12:36:02
Original
8125 people have browsed it

The upload_max_filesize and post_max_size directives determine the maximum file size that PHP allows to be uploaded on the server. By default this value is set to 2M, this value can be increased according to the requirements of the application. It is recommended not to increase this value too high on a shared server. Let's take a look at how to change the maximum upload file size limit in PHP.


How to set size limit for file upload using php

##Find the correct How to set size limit for file upload using php.ini

First, you need to find the loaded PHP configuration file (How to set size limit for file upload using php.ini) on the system. For How to set size limit for file upload using php cli, execute the command below to find the How to set size limit for file upload using php.ini file.

$ How to set size limit for file upload using php -i | grep How to set size limit for file upload using php.ini
Copy after login

For web servers like Apache/Nginx, use the How to set size limit for file upload using phpinfo() function to create a PHP script and access it in the web browser. This will show the location of the How to set size limit for file upload using php.ini file used.

Change the maximum upload file size limit

The upload_max_filesize variable defines the maximum size of files that can be uploaded. The post_max_size variable defines the maximum data size that can be posted at one time. Therefore, upload_max_filesize and post_max_size variables need to be set to change the upload maximum file size in PHP. Edit the How to set size limit for file upload using php.ini file to increase the maximum allowed upload file size. Edit the PHP configuration file "How to set size limit for file upload using php.ini" and increase the size to the following values.

; Maximum allowed size for uploaded files.
; http://How to set size limit for file upload using php.net/upload-max-filesize 

upload_max_filesize = 20M
  
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://How to set size limit for file upload using php.net/post-max-size 

post_max_size = 20M
Copy after login

Save the configuration file and restart the web server to reload the changes.

Setting the maximum file upload in PHP

Also, use a single request set max_file_uploads directive to set the maximum number of files that can be uploaded.

; 可通过单个请求上传的最大文件数
max_file_uploads = 20
Copy after login

Disabling file uploads in PHP

If our application does not require uploading files, we can disable it by setting Off to the file_uploads directive.

; Whether to allow HTTP file uploads.
; http://How to set size limit for file upload using php.net/file-uploadsfile_uploads =Off
Copy after login

The above is the detailed content of How to set size limit for file upload using php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!