PHP大文件上传获取空数组代码7

kq4fsx7k  于 2023-01-29  发布在  PHP
关注(0)|答案(1)|浏览(124)

我编写了一个页面来上传视频等文件,但我有一个超过2GB的大文件的问题
当我上传小于2GB的文件时,它工作正常,没有任何问题,但当我尝试大文件时,我得到空数组,错误代码为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代码:

<?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>';
    }
}
?>

超文本:

<!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 class="file-area">
                    <input type="file" id="file" name="file" multiple accept="video/mp4,video/*" />
                </div>
                
                <div class="simple-field">
                    <input type="submit" name="submit" id="submit" />
                </div>
            </form>
    </div>
</body>
</html>

.htaccess文件:

<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

php错误日志和apache日志中没有任何内容我在自己的服务器上使用WHM & CPanel和centos7

我试着改变

  • php值内存限制
  • php_value发布最大大小

有不同的价值观,但都是一样的

kpbwa7wx

kpbwa7wx1#

通过增加/tmp目录中的空间解决了问题
Centos7 /RHEL:

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

相关问题