简体   繁体   English

在php中上传大文件?

[英]upload large files in php?

I need to upload large files to my server (max 100mb files)我需要将大文件上传到我的服务器(最大 100mb 文件)

memory_limit = 30M
post_max_size = 192M
file_uploads = On
upload_max_filesize = 192M 
max_execution_time = 7200 sec
max_input_time = 7200 sec

these are my server details i am using apache 2.2.21 so i change LimitRequestBody to upload folders support 2GB when i upload 80 mb file it will fail to upload when i upload 10 mb files successfully upload so any idea to upload large这些是我的服务器详细信息 我使用的是 apache 2.2.21 所以我更改 LimitRequestBody 以上传文件夹支持 2GB 当我上传 80 mb 文件时它将无法上传当我上传 10 mb 文件成功上传所以任何想法上传大

Thanks for advance感谢提前

To upload a large file ( >5MB), I use the chuck upload method.要上传大文件(> 5MB),我使用chuck上传方法。

/**
 * @param $file
 * @param $fileSize
 * @param $name
 * @return int
 */
public function chunkUpload($file, $fileSize, $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;
    }
}

如果上传做“登录”的人,你还应该检查session.gc_maxlifetime

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM