广州传奇网络

地址:广州市天河区东圃大马路富华楼C座

电话:13808825895

邮箱:gz020wbs@163.com

QQ:1564443073

网址:http://www.020wbs.com/

首页 > 二次开发Ecshop二次开发 > 完整可用的远程图片本地化

二次开发Ecshop二次开发

二次开发Ecshop二次开发

完整可用的远程图片本地化

/**
* 得到远程图片
*
* @access public
* @param goods_desc $goods_desc 要处理的内容
* @return mix 如果成功返回缩略图的路径,失败则返回false
*/
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."/".date('Ym')."/body";
$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 = ereg_replace($value,$fileurl,$body);
}
}
$body = addslashes($body);
//print_r($body);
//exit();
return $body;
}
调用方式:
在goods.php中,把所有$_POST['goods_desc']改成GetCurContent($_POST['goods_desc'])
当然,最后先用变量存起来,然后直接用就行了
下载的图片路径在images/年月/body中