public static function getMd5SumForFile($filename, $from_pos, $to_pos)
    {
        $content_md5 = "";
        if (($to_pos - $from_pos) > self::OSS_MAX_PART_SIZE) {
            return $content_md5;
        }
        $filesize = filesize($filename);
        if ($from_pos >= $filesize || $to_pos >= $filesize || $from_pos < 0 || $to_pos < 0) {
            return $content_md5;
        }

        $total_length = $to_pos - $from_pos + 1;
        $buffer = 8192;
        $left_length = $total_length;
        if (!file_exists($filename)) {
            return $content_md5;
        }

        if (false === $fh = fopen($filename, 'rb')) {
            return $content_md5;
        }

        fseek($fh, $from_pos);
        $data = '';
        while (!feof($fh)) {
            if ($left_length >= $buffer) {
                $read_length = $buffer;
            } else {
                $read_length = $left_length;
            }
            if ($read_length <= 0) {
                break;
            } else {
                $data .= fread($fh, $read_length);
                $left_length = $left_length - $read_length;
            }
        }
        fclose($fh);
        $content_md5 = base64_encode(md5($data, true));
        return $content_md5;
    }
public static function getMd5SumForFile($filename, $from_pos, $to_pos)
    {
        $content_md5 = "";
        if (($to_pos - $from_pos) > self::OSS_MAX_PART_SIZE) {
            return $content_md5;
        }
        $filesize = filesize($filename);
        if ($from_pos >= $filesize || $to_pos >= $filesize || $from_pos < 0 || $to_pos < 0) {
            return $content_md5;
        }

        $total_length = $to_pos - $from_pos + 1;
        $buffer = 8192;
        $left_length = $total_length;
        if (!file_exists($filename)) {
            return $content_md5;
        }

        if (false === $fh = fopen($filename, 'rb')) {
            return $content_md5;
        }

        fseek($fh, $from_pos);
        $data = '';
        while (!feof($fh)) {
            if ($left_length >= $buffer) {
                $read_length = $buffer;
            } else {
                $read_length = $left_length;
            }
            if ($read_length <= 0) {
                break;
            } else {
                $data .= fread($fh, $read_length);
                $left_length = $left_length - $read_length;
            }
        }
        fclose($fh);
        $content_md5 = base64_encode(md5($data, true));
        return $content_md5;
    }
public static function getMd5SumForFile ( $ filename , $ from_pos , $ to_pos ) { $ content_md5 = "" ; if ( ( $ to_pos - $ from_pos ) > self :: OSS_MAX_PART_SIZE ) { return $ content_md5 ; } $ filesize = filesize ( $ filename ) ; if ( $ from_pos >= $ filesize || $ to_pos >= $ filesize || $ from_pos < 0 || $ to_pos < 0 ) { return $ content_md5 ; } $ total_length = $ to_pos - $ from_pos + 1 ; $ buffer = 8192 ; $ left_length = $ total_length ; if ( ! file_exists ( $ filename ) ) { return $ content_md5 ; } if ( false === $ fh = fopen ( $ filename , 'rb' ) ) { return $ content_md5 ; } fseek ( $ fh , $ from_pos ) ; $ data = '' ; while ( ! feof ( $ fh ) ) { if ( $ left_length >= $ buffer ) { $ read_length = $ buffer ; } else { $ read_length = $ left_length ; } if ( $ read_length <= 0 ) { break ; } else { $ data .= fread ( $ fh , $ read_length ) ; $ left_length = $ left_length - $ read_length ; } } fclose ( $ fh ) ; $ content_md5 = base64_encode ( md5 ( $ data , true ) ) ; return $ content_md5 ; }
Get MD5 of the file.

@param $filename
@param $from_pos
@param $to_pos
@return string
Get MD5 of the file .