如何确定PHP中的最大文件上传限制 [英] How to determine the max file upload limit in php

查看:374
本文介绍了如何确定PHP中的最大文件上传限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用php脚本确定php设置允许的文件上传大小?

How can the file upload size allowed by php settings be determined withing a php script?

推荐答案

上传受三个选项限制: upload_max_filesize post_max_size memory_limit >.您的上传只有在没有其中之一的情况下才能完成.

The upload is limited by three options: upload_max_filesize, post_max_size and memory_limit. Your upload is only done if it doesn't exeed one of them.

ini_get()函数为您提供了一个简短的限制,应该首先进行转换.为此,请转至 AoEmaster .

The ini_get() function provides you with a short hand of the limit and should be converted first. Thx to AoEmaster for this.

function return_bytes($val) {
    $val = trim($val);
    $last = strtolower($val[strlen($val)-1]);
    switch($last) 
    {
        case 'g':
        $val *= 1024;
        case 'm':
        $val *= 1024;
        case 'k':
        $val *= 1024;
    }
    return $val;
}

function max_file_upload_in_bytes() {
    //select maximum upload size
    $max_upload = return_bytes(ini_get('upload_max_filesize'));
    //select post limit
    $max_post = return_bytes(ini_get('post_max_size'));
    //select memory limit
    $memory_limit = return_bytes(ini_get('memory_limit'));
    // return the smallest of them, this defines the real limit
    return min($max_upload, $max_post, $memory_limit);
}

来源: http://www.kavoir.com/2010/02/php-get-the-file-uploading-limit-max-file-size-allowed-to-upload.html

这篇关于如何确定PHP中的最大文件上传限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆