private function dowloadPicture($content) { include PUBLICPATH . '/vendor/httpdown.class.php'; //截取内容图片路径正则 $rule = "/(src)=[\"|'| ]{0,}([^>]*\\.(gif|jpg|bmp|png|jpeg))/isU"; if (preg_match($rule, $content, $array)) { $url = str_replace("\"", "", $array[2]); if (strpos($url, 'http://') === false) { return $url; } if (!stristr($url, $GLOBALS['cfg_basehost'])) { $htd = new HttpDown(); //实例化 $htd->OpenUrl($url); $sparr = array("image peg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp"); if (!in_array($htd->GetHead("content-type"), $sparr)) { return ''; } else { $date = date("Ymd"); $name = date("YmdHis") . rand(1, 50); $path = UPLOADPATH . "/arcimgs/"; $url = $path . $date . "/"; $imgUrl = $url . $name; //创建路径 if (!file_exists($url)) { mkdir($url); } $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'; } } } $fileurl = $imgUrl . $itype; $ok = $htd->SaveToBin($fileurl); $litpic = $fileurl; $litpic = Common::thumb($litpic, $litpic, 240, 180); $litpic = str_replace(BASEPATH, '', $litpic); //去掉头 $litpic = str_replace('\\', '/', $litpic); } } else { $litpic = $url; } return $litpic; } }
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 : ''; }