Beispiel #1
0
function GetRemPic($url)
{
    global $cfg_image_dir;
    //引入下载类
    require_once PHPMYWIND_DATA . '/httpfile/down.class.php';
    //初始化变量
    $htd = new HttpDown();
    $htd->OpenUrl($url);
    //判断文件类型
    $sparr = array('image/pjpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/xpng', 'image/wbmp');
    if (!in_array($htd->GetHead("content-type"), $sparr)) {
        return FALSE;
    } else {
        $type = $htd->GetHead("content-type");
        if ($type == 'image/gif') {
            $tempfile_ext = 'gif';
        } else {
            if ($type == 'image/png') {
                $tempfile_ext = 'png';
            } else {
                if ($type == 'image/wbmp') {
                    $tempfile_ext = 'bmp';
                } else {
                    $tempfile_ext = 'jpg';
                }
            }
        }
        $upload_url = 'image';
        $upload_dir = $cfg_image_dir;
        $ymd = date('Ymd');
        $upload_url .= '/' . $ymd;
        $upload_dir .= '/' . $ymd;
        if (!file_exists($upload_dir)) {
            mkdir($upload_dir);
            $fp = fopen($upload_dir . '/index.htm', 'w');
            fclose($fp);
        }
        //上传文件名称
        $filename = time() + rand(1, 9999) . '.' . $tempfile_ext;
        //上传文件路径
        $save_url = 'uploads/' . $upload_url . '/' . $filename;
        $save_dir = $upload_dir . '/' . $filename;
        $rs = $htd->SaveToBin($save_dir);
    }
    $htd->Close();
    return $rs ? $save_url : '';
}
function GetRemoteImage($url, $filename = "", $filepath = "order")
{
    include_once 'httpdown.class.php';
    //上传目录按照日期来建立 每月一个
    $savePath = "../attachment/{$filepath}/" . date("Ym");
    $savePath2 = "attachment/{$filepath}/" . date("Ym") . '/';
    //存储数据库目录
    $savePath = substr(str_replace("\\", "/", $savePath), -1) == "/" ? $savePath : $savePath . "/";
    if (!is_dir($savePath)) {
        createDir($savePath);
    }
    //目录不存在就创建一个
    $revalues = array();
    $ok = false;
    $htd = new HttpDown();
    $htd->OpenUrl($url);
    $sparr = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp");
    if (!in_array($htd->GetHead("content-type"), $sparr)) {
        return '';
    } else {
        $itype = $htd->GetHead("content-type");
        if ($itype == "image/gif") {
            $itype = '.gif';
        } else {
            if ($itype == "image/png") {
                $itype = '.png';
            } else {
                if ($itype == "image/wbmp") {
                    $itype = '.bmp';
                } else {
                    $itype = '.jpg';
                }
            }
        }
        if (!empty($filename)) {
            $savename = $filename;
        } else {
            $savename = date('YmdHis') . "_" . rand(100, 999) . $itype;
            //判断文件是否存在,不允许重复文件
            if (file_exists($savePath . $savename)) {
                $savename = date('YmdHis') . "_" . rand(100, 999) . $itype;
            }
        }
        $ok = $htd->SaveToBin($savePath . $savename);
        if ($ok) {
            $revalues['filepath'] = $savePath2 . $savename;
            $revalues['filename'] = $savename;
            $revalues['savepath'] = $savePath2;
        }
    }
    $htd->Close();
    return $ok ? $revalues : '';
}