最大文件上传限制php

时间:2015-10-13 11:44:16

标签: php

我想避免以下错误

  

警告:POST内容长度13610816字节超过了第0行未知的10485760字节限制

我已经在我的php.ini文件中设置了upload_max_filesize,post_max_size和memory_limit,但我从stackoverflow获得了以下代码,虽然它似乎无法正常工作。请帮忙

if($_SERVER['REQUEST_METHOD'] == 'POST' 
&& empty($_POST)
&& empty($_FILES)
&& $_SERVER['CONTENT_LENGTH'] > 0){

$displayMaxSize = ini_get('post_max_size');

switch(substr($displayMaxSize,-1)) {

case 'G':
  $displayMaxSize = $displayMaxSize * 1024;
case 'M':
  $displayMaxSize = $displayMaxSize * 1024;
case 'K':
   $displayMaxSize = $displayMaxSize * 1024;
}

$error = 'Posted data is too large. '.
       $_SERVER['CONTENT_LENGTH'].
       ' bytes exceeds the maximum size of '.
       $displayMaxSize.' bytes.';
}

2 个答案:

答案 0 :(得分:2)

通过文件上传找到这个

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

通过upload_max找到这个

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 128M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

答案 1 :(得分:-1)

将此代码置于页面顶部并更改所需的值

ini_set(' post_max_size',' 100M'); ini_set(' upload_max_filesize',' 100M');