【问题标题】:Get the last chunk of upload file获取上传文件的最后一块
【发布时间】:2015-01-20 07:55:41
【问题描述】:

所以基本上https://github.com/blueimp/jQuery-File-Upload/wiki 作为上传者,我正在使用它的块功能在服务器端移动。我在获取上传文件的最后一块时遇到问题。

我要做的只是在块到达最后一个块或上传者完成上传块时只保存到 db

例如。块大小 = 10mb

if( isset($_SERVER['HTTP_CONTENT_RANGE']) )
    {


$content_range = preg_split('/[^0-9]+/', $_SERVER['HTTP_CONTENT_RANGE']);

// if file is greater or equal to 10mb
if( $content_range[2] + 1 == $content_range[3] )
    {
        insert data to database here
    } 
    // if file does not need to be chunked file is less than chunk size
    else
    {
        also insert the data to database
    }

}

【问题讨论】:

    标签: php chunked-encoding


    【解决方案1】:
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $is_chunked_upload = !empty($_SERVER['HTTP_CONTENT_RANGE']);
        if ($is_chunked_upload) {
            $is_last_chunk = false;
    
            // [HTTP_CONTENT_RANGE] => bytes 10000000-17679248/17679249 - last chunk looks like this
    
            if (preg_match('|(\d+)/(\d+)|', $_SERVER['HTTP_CONTENT_RANGE'], $range)) {
    
                if ($range[1] == $range[2] - 1) {
                    $is_last_chunk = true;
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-27
      • 1970-01-01
      • 2019-10-06
      • 1970-01-01
      • 1970-01-01
      • 2018-10-11
      • 1970-01-01
      • 2020-01-15
      相关资源
      最近更新 更多