Skip to content Skip to sidebar Skip to footer

Restricting The Uploading Files Size In Php

I am working with multiple file upload in PHP and I also fixed an upload limit of 10MB using the following HTML commands in an upload form PHP file:

Solution 1:

You can add the following line to your target script that handle your form:

ini_set('upload_max_filesize', '10M');

Or if you can access your php.ini, just change the following :

upload_max_filesize = 10M

Manual page : http://php.net/manual/en/ini.core.php


Solution 2:

Try this

<?php
if(isset($_POST["file_uploaded"])){
    $f_id= $_GET["id"]; 
    $dir_name="dir_hal_".$f_id; 
    $u=0; 
    if(!is_dir($dir_name))
    {
        mkdir($dir_name); 
    }
    $dir=$dir_name."/"; 
    $file_realname = $_FILES['infile']['name'];
    $c=count($_FILES['infile']['name']);
    for($i = 0;$i<$c;$i++) 
    {
        $ext = substr(strrchr($_FILES['infile']['name'][$i], "."), 1); 
        $fname = substr($_FILES['infile']['name'][$i],0,strpos($_FILES['infile']['name'][$i], "."));
        $fPath = $fname."_(".substr(md5(rand() * time()),0,4).")".".$ext"; 
        if($_FILES["infile"]["size"][$i]>10000000)
        {
            echo 'File uploaded exceeds maximum upload size.';
        }
        else{
            if(move_uploaded_file($_FILES['infile']['tmp_name'][$i], $dir . $fPath)) 
            {
                $u=$u+1;
                echo "Upload is successful\n";
            }
            else 
            {
                echo "error\n"; 
            }
        }
    }
    if($u==$c)
    {
        echo "count is correct";
    }
}
?>

Post a Comment for "Restricting The Uploading Files Size In Php"