-1

我必须将 php max 文件上传到 50 GB。服务器有能力,但我对如何完成这项任务感到困惑。

我的第一个问题:是否可以在 php 中一次上传 50 GB 的文件?

第二个问题:如果可能的话,有没有办法以块的形式上传文件,所以如果由于某种原因失去连接会更好,这样它就会从剩下的块继续,上传的块将保留在服务器中。

抱歉,我在 PHP 方面没有太多经验,也从未做过这样的任务。我尝试谷歌但找不到任何解决方案。

谢谢

4

2 回答 2

0

1.有可能,但这取决于许多因素,例如您的互联网连接(执行超时)、PHP 版本和 PHP 设置。

post_max_size = 0
upload_max_filesize = 0

2.不应该考虑发送这么大的文件而不分块。它可以使用 HTTP(不推荐)和 JS/PHP 之外的其他协议来实现。

看看其他的答案,因为这个话题被提到很多次并且有很多库,即 在PHP中使用分块上传1GB文件

于 2020-06-17T17:09:23.600 回答
0

To upload a large file you can consider the two most important things

  • Good internet connection
  • Upload file chunk by chunk

I use the below code to upload a large file that is greater than 5MB. You can increase the chunk size. Although I don't know your file type. You may try.

/**
 * @param $file
 * @param $fileSize
 * @param $name
 * @return int
 */
public function chunkUpload($file, $fileSize, $applicantID, $name) {
    
    $targetFile     = 'upload/'. $name;
    $chunkSize      = 256; // chunk in bytes
    $uploadStart    = 0;

    $handle = fopen($file, "rb");
    $fp     = fopen($targetFile, 'w');

    # Start uploading
    try {
    
        while($uploadStart < $fileSize) {
        
            $contents = fread($handle, $chunkSize);
            fwrite($fp, $contents);
        
            $uploadStart += strlen($contents);
            fseek($handle, $uploadStart);
        }
    
        fclose($handle);
        fclose($fp);
        
        return 200;
        
    } catch (\Exception $e) {
        return 400;
    }
}
于 2020-09-03T20:41:00.463 回答