/**(V6.7 新增)(V6.8 更新) * 下载远程图片 * @param string $content * @param string $targeturl * @return string */ function down_remote_img($content, $targeturl = ''){ preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png|webp))\\2/i", $content, $img_array); $img_array = isset($img_array[3]) ? array_unique($img_array[3]) : array(); if($img_array) { $path = C('upload_file').'/'.date('Ym/d'); $urlpath = SITE_PATH.$path; $imgpath = YZMPHP_PATH.$path; if(!is_dir($imgpath)) @mkdir($imgpath, 0777, true); } $down_ignore_domain = get_config('down_ignore_domain'); $down_ignore_domain = $down_ignore_domain ? explode(',', $down_ignore_domain) : array(); array_push($down_ignore_domain, HTTP_HOST); foreach($img_array as $value){ foreach($down_ignore_domain as $ignore_domain){ if(stristr($value, $ignore_domain)) continue 2; } $val = $value; if(strpos($value, 'http') === false){ if(!$targeturl) continue; $value = $targeturl.$value; } if(strpos($value, '?')){ $value = explode('?', $value); $value = $value[0]; } $ext = fileext($value); if(!is_img($ext)) continue; $imgname = date('YmdHis').rand(100,999).'.'.$ext; $filename = $imgpath.'/'.$imgname; $urlname = $urlpath.'/'.$imgname; ob_start(); readfile($value); $data = ob_get_contents(); ob_end_clean(); $len = $data ? file_put_contents($filename, $data) : 0; if($len){ $arr = array( 'siteid' => get_siteid(), 'originname' => '远程下载-'.htmlspecialchars(basename($value)), 'filename' => $imgname, 'filepath' => $urlpath.'/', 'filesize' => $len, 'fileext' => $ext, 'module' => ROUTE_M, 'isimage' => 1, 'userid' => isset($_SESSION['adminid']) ? $_SESSION['adminid'] : $_SESSION['_userid'], 'username' => isset($_SESSION['adminname']) ? $_SESSION['adminname'] : $_SESSION['_username'], 'uploadtime' => SYS_TIME, 'uploadip' => getip() ); D('attachment')->insert($arr); $content = str_replace($val, $urlname, $content); } } return $content; }
down_remote_img
上一篇:is_childid
下一篇:content_total
有问题可以加入织梦技术QQ群一起交流学习
本站vip会员 请加入 VIP②群 PS:加入时备注用户名或昵称
普通注册会员或访客 请加入技术交流②群
作者:54818模板网 关注:351 时间:2023-04-04 15:09:51
相关网站教程: