简体   繁体   中英

How to allow limited size file upload in php?

I have a website hosted on a PC I have no access to. I have an upload form allowing people to upload files up to 30MB big. My server side script is done in PHP..then how can i set size limit in php ?

You can use this for limiting your file size..

ini_set("post_max_size", "30M");
ini_set("upload_max_filesize", "30M");
ini_set("memory_limit", "20000M"); 

Try increasing the following values in your php.ini file, for example:

    memory_limit = 99M
    max_execution_time = 300
    upload_max_filesize = 30M
    post_max_size = 24M

Getting File Size in PHP is done in the following way

$filesize = $_FILES['file']['size'];

Here you can get the file size and can check for the size to be limited to

if($filesize<yourmaxsize)
{
    //do something
}

If you want file size of 30MB to be uploadable then There is some thing called as maximum size that can be uploaded generally it will be 2MB i think you can go to php.ini (configuration file) and change its size to 30MB or 50MB whatever the size you want

in your php configure file which known as php.ini, there is parameter called upload_max_filesize, you can change that value to what you want. that will be affected to your all php applications.

if(isset($_FILES['uploaded_file'])) {

    $maxsize = 2097152;

    if(($_FILES['uploaded_file']['size'] >= $maxsize) || ($_FILES["uploaded_file"])) { 
       //alert for large size
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM