How to set PHP file upload size limit

Source: Internet
Author: User
Tags file upload php file upload

I. If php does not limit the upload size, we can limit the upload size when uploading, as shown in

 

The code is as follows: Copy code
$ Maxattachsize = 5097152; // maximum upload size. The default value is 2 MB.
$ Temppath = $ upfile ['tmp _ name'];
$ Filesize = filesize ($ temppath );
If ($ filesize> $ maxattachsize) $ err = 'File size exceeds '. $ maxattachsize.' Byte ';

In this way, only 2 MB files can be uploaded.


2. Modify post_max_size and upload_max_filesize in php. ini.

1. memory_limit memory settings

2. max_execution_time

3. Maximum post_max_size POST data limit

4. Maximum size of uploaded files in upload_max_filesize

Example

The code is as follows: Copy code

Max_execution_time = 30; Maximum execution time of each script, in seconds
Max_input_time = 60; Maximum amount of time each script may spend parsing request data
; Max_input_nesting_level = 64; Maximum input variable nesting level
Memory_limit = 128 M; Maximum amount of memory a script may consume (128 MB)

; Maximum size of POST data that PHP will accept.
Post_max_size = 105 M

; Maximum allowed size for uploaded files.
Upload_max_filesize = 100 M

Tips: If you are uploading large files, we 'd better add the execution time set_time_limit to the page.

The code is as follows: Copy code

Set_time_limit (0 );

In this way, no timeout will occur.

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.