尝试上传大文件时,如何解决浏览器 window 无响应的问题?

How to fix no response on browser window when trying to upload large files?

我想上传通常总大小超过 1 GB 的电影或大量视频,PHP 代码已经适用于小文件(1 GB 以下)和少量视频(5 或更少) ).但是当我尝试上传更大的文件时,发生了无数错误,例如 chrome 重置 window,即使脚本完成,文件也没有上传,只是浏览器变白而服务器没有响应或简单地说错误 504,网关超时。

我已经将我的 php.ini 文件配置为接受文件数量和文件大小,我使用的 nginx 服务器也配置为接受文件上传,所以我不知道这些错误是什么来自.

<?php
if(isset($_POST["submit"])){
     $Pass = $_POST["Pass"];
    if($Pass === "Master"){
        $Passok = 1;
        $uploadOk = 1;
        echo "Password Correct";
        echo nl2br("\n");
    }else{
        echo "Password Incorrect";
        echo nl2br("\n");
        exit;
    }

    if($Passok==1){
    nl2br("\n");
    echo "<br/>";

    $filecount= sizeof($_FILES["userfiles"]["name"]);
    echo "Number of files uploaded: ".$filecount;
    echo "<br/>";
    echo "Original Name of Files: ";
    echo "<br/>";
    for($x=0; $x < $filecount;$x++){
    echo $_FILES["userfiles"]["name"][$x];
    echo "<br/>";
    }

        #$_FILES["fileToUpload"]["name"] = $FinalName;
        #$target_file = $target_dir.$FinalName;
    echo "Modified Name of Files:";
    for($x=0; $x < $filecount;$x++){
    #Naming change
    $target_dir = "../Mount/";
    $FileType = strtolower(pathinfo($target_dir . basename($_FILES["userfiles"]["name"][$x]),PATHINFO_EXTENSION));
    $NameofFile=basename($_FILES["userfiles"]["name"][$x]);
    $filter1= filter_var($NameofFile,FILTER_SANITIZE_SPECIAL_CHARS);
    $finalfilter = preg_replace ('/[^\p{L},p{N}]/u', '', $filter1);
    $FinalName=$finalfilter.".".$FileType;
    echo "<br/>";
    echo $FinalName;
    echo "<br/>";
    $_FILES["userfiles"]["name"][$x]=$FinalName;
    $target_file = $target_dir . basename($_FILES["userfiles"]["name"][$x]);
    #$FileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
    #Naming change
    #Check if file Exists
    if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
    #Check File Size
    if ($_FILES["userfiles"]["size"][$x] > 9000000000){  
    echo "Sorry,file is too large, wont upload, max size is 9gigabites";
    $uploadOk = 0;
}
#Upload
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["userfiles"]["tmp_name"][$x], $target_file)) {
        echo "The file ". $FinalName. " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
    }


    echo "<br/>";

    }






} #end of Pass if   


}

?>

通常适用于大多数小文件,但是当文件变大时它会失败,我不知道为什么。

尝试通过在 php.ini

中添加此代码来更新执行时间和 post 大小
max_execution_time = 1800
max_input_time = -1
post_max_size = 2048M
upload_max_filesize = 2048M
memory_limit = 256M

在 nginx.conf 中设置 Nginx 超时和数据包最大主体大小或在 /etc/nginx/sites-available 中设置配置文件(或启用站点)

proxy_connect_timeout       300; # (5 minutes)
proxy_send_timeout          300;
proxy_read_timeout          300;
send_timeout                300;
client_max_body_size      2048M; # (2 GB)

然后使用 sudo nginx -t 检查配置,如果正常,使用 sudo service nginx reload

重新加载配置