Home > Mobile >  Php large file upload get empty array with code 7
Php large file upload get empty array with code 7

Time:01-31

I programmed a page to upload files like videos, But I have a problem with large file more than 2GB

When I upload file less than 2GB it's working fine with out any problem, But when I try large file I get empty array with error code 7

array(1) { 
    ["file"]=> array(5) { 
        ["name"]=> string(15) "12345648465.mp4" 
        ["type"]=> string(0) "" 
        ["tmp_name"]=> string(0) "" 
        ["error"]=> int(7) 
        ["size"]=> int(0) 
    } 
} 

php code :

<?php
include '../conn.php';


if(isset($_POST['submit'])){
    
    $videos_path = '../testvideos/';
    
    $video = $_FILES["file"]["name"];
    $tmp_video = $_FILES['file']['tmp_name'];
    $name = explode('.',$video);
    $real_name = $name[0];
    
    $video_file = $videos_path . $real_name;

    if (!file_exists($video_file)) {
        var_dump($_FILES);
        if (is_uploaded_file($tmp_video)) {

            mkdir($video_file, 0777, true);
            if(move_uploaded_file($tmp_video,$video_file.'/'.$video)){
                print_r($real_name);
            }else{
                print_r($_FILES); 
            }
        }
    }else {
        echo '<script>alert(file already exist);</script>';
    }
}
?>

HTML :

<!DOCTYPE html>
<html>
<head>
    <title>Test Upload</title>
</head>
<body>
    <div>
        <form action="index.php?action=upload" method="post" id="upload-form" enctype="multipart/form-data">
                <div >
                    <input type="file" id="file" name="file" multiple accept="video/mp4,video/*" />
                </div>
                
                <div >
                    <input type="submit" name="submit" id="submit" />
                </div>
            </form>
    </div>
</body>
</html>

.htaccess file :

<IfModule php8_module>
   php_flag display_errors On
   php_value max_execution_time 20000
   php_value max_input_time 20000
   php_value max_input_vars 1000
   php_value memory_limit 8G
   php_value post_max_size 4G
   php_value session.gc_maxlifetime 1440
   php_value upload_max_filesize 20G
   php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
   php_flag display_errors On
   php_value max_execution_time 20000
   php_value max_input_time 20000
   php_value max_input_vars 1000
   php_value memory_limit 8G
   php_value post_max_size 4G
   php_value session.gc_maxlifetime 1440
   php_value upload_max_filesize 20G
   php_flag zlib.output_compression Off
</IfModule>

limitRequestBody 5368709120

there's nothing in php error log and apache logs I use WHM & CPanel with centos7 on my own server

I tried to change

  • php_value memory_limit
  • php_value post_max_size

with different values but same thing

CodePudding user response:

Problem solved by increase space in /tmp directory

Centos7 /RHEL :

# mount -t tmpfs -o size=10485760000,mode=1777 overflow /tmp
  • Related