Home > php教程 > php手册 > 如何设置PHP上传文件大小限制

如何设置PHP上传文件大小限制

WBOY
Release: 2016-05-25 16:55:12
Original
1032 people have browsed it
使用php的同学都会知道上传文件我们默认情况在php只会支持2MB文件上传大小了,如果超过了就无法上传了,下面我来给大家介绍如何设置PHP上传文件大小限制吧。

一,如果php没有限制我们可以在上传时就限制上传大小,如

 

 代码如下 复制代码
$maxattachsize=5097152;//最大上传大小,默认是2m
$temppath=$upfile['tmp_name'];
$filesize=filesize($temppath);
if($filesize > $maxattachsize)$err='文件大小超过'.$maxattachsize.'字节';

这样就限制了文件只能上传2MB大小的文件了


二,修改php.ini中的post_max_size和upload_max_filesize

1、memory_limit内存设置限制

2、max_execution_time程序执行时间限制

3、post_max_size最大POST数据限制

4、upload_max_filesize最大上传文件大小限制

 代码如下 复制代码

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 = 128M      ; Maximum amount of memory a script may consume (128MB)

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

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

小提示,如果你是上传大文件我们最好在页面加上执行时间set_time_limit

 代码如下 复制代码

set_time_limit(0);

这样就不会超时了



文章地址:

转载随意^^请带上本文地址!

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template