ecshop 远程图片本地化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | define( 'IN_ECS' , true); require (dirname( __FILE__ ) . '/includes/init.php' ); $smarty ->assign( 'siteDomain' , 'http://' . $_SERVER [ 'HTTP_HOST' ]. '/' ); /** * 得到远程图片 * * @access public * @param goods_desc $goods_desc 要处理的内容 * @return mix 如果成功返回缩略图的路径,失败则返回false */ $str = '<p> <img src= "http://dealer0.autoimg.cn/dl/10982/newsimg/130364690780019046.jpg" /> <img src= "http://photocdn.sohu.com/20151028/mp38321387_1446018553478_10.jpeg" /> </p> <p style= "word-wrap: break-word; white-space: normal; word-spacing: 0px; text-transform: none; word-break: normal; color: rgb(34,34,34); outline-width: medium; padding-bottom: 17px; padding-top: 0px; font: 16px/30px tahoma, arial, 'Microsoft YaHei'; outline-style: none; padding-left: 0px; widows: 1; margin: 0px; letter-spacing: normal; outline-color: invert; padding-right: 0px; background-color: rgb(245,248,253); text-indent: 0px; -webkit-text-stroke-width: 0px" > ddddddddddddddddddddddddddddddddd </p>'; $test = GetCurContent( $str ); function GetCurContent( $goods_desc ) { $body = stripslashes ( $goods_desc ); $img_array = array (); //$body = ereg_replace("HTTP://".$_SERVER['SERVER_NAME']."/","",$body);//将源文件进行替换 preg_match_all( "/src=[\"|'|\s]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU" , $body , $img_array ); $img_array = array_unique ( $img_array [1]); set_time_limit(0); $imgurl = IMAGE_DIR. "/bdimages/upload1/" . date ( 'Ymd' ); $imgpath = ROOT_PATH. $imgurl ; $millisecond = date ( "YmdHms" ); if (! file_exists ( $imgpath )) { if (!make_dir( $imgpath )) { return false; } } else { foreach ( $img_array as $key => $value ) { $value = trim( $value ); $get_file = @ file_get_contents ( $value ); $rndfilename = $imgpath . "/" . $millisecond . $key . "." . substr ( $value ,-3,3); $fileurl = "http://" . $_SERVER [ 'SERVER_NAME' ]. "/" . $imgurl . "/" . $millisecond . $key . "." . substr ( $value ,-3,3); // $fileurl = "/".$imgurl."/".$millisecond.$key.".".substr($value,-3,3); if ( $get_file ) { $fp = @ fopen ( $rndfilename , "w" ); @fwrite( $fp , $get_file ); @fclose( $fp ); } //echo $rndfilename."<br/>".$fileurl."<br/>"; $body = str_replace ( $value , $fileurl , $body );; echo $body ; } } $body = addslashes ( $body ); return $body ; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)