Ejemplo n.º 1
0
 /**
 +----------------------------------------------------------
 * 获取文件的mime_content类型
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 */
 function mime_content_type($filename)
 {
     $contentType = GetContentType();
     $type = strtolower(substr(strrchr($filename, '.'), 1));
     if (isset($contentType[$type])) {
         $mime = $contentType[$type];
     } else {
         $mime = 'application/octet-stream';
     }
     return $mime;
 }
Ejemplo n.º 2
0
function get_img_content($img_url, $snoopy_obj = '', $ext = '')
{
    $pick_config = get_pick_set();
    if (!function_exists('fsockopen') && !function_exists('pfsockopen') || !$snoopy_obj) {
        $content = dfsockopen($img_url);
    } else {
        if ($pick_config['is_set_referer'] == 1) {
            $snoopy_obj->referer = $img_url;
        }
        //有些图片设置了这个反而采集不到比如:http://img1.gxcity.com/forum/201107/14/135857bbq214kkgbabz42m.jpg
        //有些必须设置这个 http://abbs.cn/pic/2012/03/08/1331168643.jpg  					//http://www.biketo.com/d/file/news/bikenews/2012-09-05/d8ca0bad794a799354fdad835742783f.jpg
        $snoopy_obj->fetch($img_url);
        $content = $snoopy_obj->results;
        $headers = $snoopy_obj->headers;
        if ($snoopy_obj->status == '403') {
            $snoopy_obj->referer = '';
            $snoopy_obj->fetch($img_url);
            $content = $snoopy_obj->results;
            $headers = $snoopy_obj->headers;
        }
        if ($snoopy_obj->status == '404' || $snoopy_obj->status == '403') {
            return FALSE;
        }
        foreach ($headers as $v) {
            $v_arr = explode(':', $v);
            if ($v_arr[1]) {
                $header_arr[strtolower($v_arr[0])] = trim($v_arr[1]);
            }
        }
        pload('F:http');
        $info['size'] = $header_arr['content-length'];
        $url_info = parse_url($img_url);
        $query_url = $url_info['query'] ? $url_info['query'] : $url_info['path'];
        $info['file_ext'] = addslashes(strtolower(substr(strrchr($query_url, '.'), 1, 10)));
        if ($header_arr['content-disposition']) {
            $c_d = $header_arr['content-disposition'];
            $info_arr = explode(';', $c_d);
            $file_arr = explode('=', $info_arr[1]);
            $arr[2] = preg_replace('(\'|\\")', '', $file_arr[1]);
            //去掉引号
            $file_name = $info['file_name'] = str_iconv($arr[2]);
            $info['file_ext'] = $info['file_ext'] ? $info['file_ext'] : addslashes(strtolower(substr(strrchr($file_name, '.'), 1, 10)));
            $info['content'] = $content;
            return $info;
        } else {
            if (!$info['file_ext']) {
                $content_type = array_flip(GetContentType());
                $header_arr['content-type'] = str_replace(';', '', $header_arr['content-type']);
                $info['file_ext'] = $content_type[$header_arr['content-type']];
            }
        }
        if ($info['file_ext']) {
            $patharr = explode('/', $img_url);
            $info['file_name'] = trim($patharr[count($patharr) - 1]);
            if (strexists($info['file_name'], 'forum.php?mod=attachment')) {
                $info['file_name'] = $info['file_ext'] = '';
            }
        }
        $info['content'] = $content;
        if ($ext == 'no_get') {
            return $info;
        }
    }
    return $content;
}
Ejemplo n.º 3
0
function AddResource($host, $port, $inf_id, $radl)
{
    $headers = array('Accept: text/*', 'Content-Length: ' . strlen($radl), 'Content-Type: ' . GetContentType($radl));
    $res = BasicRESTCall("POST", $host, $port, '/infrastructures/' . $inf_id, $headers, $radl);
    return $res->getOutput();
}