bootstrap.php ➔ getUpyunFileSize()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 1
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
<?php
2
require dirname(__DIR__) . '/vendor/autoload.php';
3
4
define('USER_NAME', 'tester');
5
define('PWD', 'grjxv2mxELR3');
6
define('BUCKET', 'sdkimg');
7
define('PIC_PATH', dirname(__FILE__) . '/assets/sample.jpeg');
8
define('PIC_SIZE', filesize(PIC_PATH));
9
10
function getFileUrl($path)
11
{
12
    return "http://" . BUCKET . ".b0.upaiyun.com/" . ltrim($path, '/');
13
}
14
15
function getUpyunFileSize($path)
16
{
17
    $url = getFileUrl($path);
18
    $ch = curl_init($url);
19
    curl_setopt($ch, CURLOPT_NOBODY, true);
20
    curl_setopt($ch, CURLOPT_HEADER, true);
21
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
22
    $return = curl_exec($ch);
23
    preg_match('~^HTTP/1.1 (\d{3})~', $return, $match1);
24
    preg_match('~Content-Length: (\d+)~', $return, $match2);
25
26
    if (isset($match1[1]) && $match1[1] == 200) {
27
        return isset($match2[1]) ? intval($match2[1]) : false;
28
    } else {
29
        return false;
30
    }
31
}
32