获取上传文件的最后一个区块


Get the last chunk of upload file

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

我正在尝试做的是仅在块到达最后一个块或上传者完成上传块时保存到数据库

例如,区块大小 = 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
    }
}
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;
            }
        }
    }
}