ecshop编辑商品,远程图片自动本地化插件,自动上传外链图片

1、admin\templates\goods_info.htm

 {$FCKeditor}下载远程图片和资源 

 

2、 admin\goods.php

    if (empty($_POST['goods_sn'])){  

    }else{

    }

 在这个下面添加代码:

$remote = !empty($_POST['remote']) ? $_POST['remote'] : 0;

 //保存远程资源

if($remote == 'true')

{

$goods_desc = GetContFile($_POST['goods_desc']);

}else{

  $goods_desc = $_POST['goods_desc'];

}

 

3、admin\includes\lib_main.php文件下添加

 

//上传文件保存路径

$cfg_image_dir = ROOT_PATH .'/images';

$cfg_soft_dir  = ROOT_PATH .'/soft';

$cfg_media_dir = ROOT_PATH .'/media';

//获得文章内容里的外部资源

function GetContFile($body)

{

global $cfg_image_dir;

//引入下载类

include_once(ROOT_PATH . 'includes/httpfile/down.class.php');

//初始化变量

$body = stripslashes($body);

$host = 'http://'.$_SERVER['HTTP_HOST'];

//过滤图片文件

$pic_arr = array();

preg_match_all("/src=[\"|'|\s]{0,}(http:\/\/([^>]*)\.(gif|jpg|png|bmp))/isU", $body, $pic_arr);

$pic_arr = array_unique($pic_arr[1]);

//初始化下载类

$htd = new HttpDown();

    foreach($pic_arr as $k=>$v)

    {

        if(preg_match('#'.$host.'#i', $v)) continue;

        if(!preg_match('#^http:\/\/#i', $v)) continue;

        $htd->OpenUrl($v);

        $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 = 'images';

$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 = '../'.$upload_url.'/'.$filename;

//生成本地路径

$self = explode('/', $_SERVER['PHP_SELF']);

$self_size = count($self) - 2;

$self_str  = '';

for($i=0; $i<$self_size; $i++)

{

$self_str .= $self[$i].'/';

}

   $save_url = $self_str.'../'.$upload_url.'/'.$filename;

   $save_dir = $upload_dir.'/'.$filename;

        $rs = $htd->SaveToBin($save_dir);

        if($rs)

        {

            $body = str_replace(trim($v), $save_url, $body);

        }

    }

    $htd->Close();

//回传转义字符串

    return addslashes($body);

}

 

4、这里修改,admin\goods.php

 

    if ($is_insert)

    {

        if ($code == '')

        {

            $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .

                    "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .

                    "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .

                    "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " .

                    "is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, rank_integral, suppliers_id)" .

                "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .

                    "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".

                    "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".

                    "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".

                    " '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', $is_shipping, ".

                    " '$goods_desc', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral', '$suppliers_id')";

        }

        else

        {

            $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .

                    "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .

                    "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .

                    "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, is_real, " .

                    "is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral)" .

                "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .

                    "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".

                    "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".

                    "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".

                    " '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', 0, '$is_on_sale', '$is_alone_sale', $is_shipping, ".

                    " '$goods_desc', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral')";

        }

    }

    else

    {

        

        $sql = "SELECT goods_thumb, goods_img, original_img " .

                    " FROM " . $ecs->table('goods') .

                    " WHERE goods_id = '$_REQUEST[goods_id]'";

        $row = $db->getRow($sql);

        if ($proc_thumb && $goods_img && $row['goods_img'] && !goods_parse_url($row['goods_img']))

        {

            @unlink(ROOT_PATH . $row['goods_img']);

            @unlink(ROOT_PATH . $row['original_img']);

        }

        if ($proc_thumb && $goods_thumb && $row['goods_thumb'] && !goods_parse_url($row['goods_thumb']))

        {

            @unlink(ROOT_PATH . $row['goods_thumb']);

        }

        $sql = "UPDATE " . $ecs->table('goods') . " SET " .

                "goods_name = '$_POST[goods_name]', " .

                "goods_name_style = '$goods_name_style', " .

                "goods_sn = '$goods_sn', " .

                "cat_id = '$catgory_id', " .

                "brand_id = '$brand_id', " .

                "shop_price = '$shop_price', " .

                "market_price = '$market_price', " .

                "is_promote = '$is_promote', " .

                "promote_price = '$promote_price', " .

                "promote_start_date = '$promote_start_date', " .

                "suppliers_id = '$suppliers_id', " .

                "promote_end_date = '$promote_end_date', ";

        

        if ($goods_img)

        {

            $sql .= "goods_img = '$goods_img', original_img = '$original_img', ";

        }

        if ($goods_thumb)

        {

            $sql .= "goods_thumb = '$goods_thumb', ";

        }

        if ($code != '')

        {

            $sql .= "is_real=0, extension_code='$code', ";

        }

        $sql .= "keywords = '$_POST[keywords]', " .

                "goods_brief = '$_POST[goods_brief]', " .

                "seller_note = '$_POST[seller_note]', " .

                "goods_weight = '$goods_weight'," .

                "goods_number = '$goods_number', " .

                "warn_number = '$warn_number', " .

                "integral = '$_POST[integral]', " .

                "give_integral = '$give_integral', " .

                "rank_integral = '$rank_integral', " .

                "is_best = '$is_best', " .

                "is_new = '$is_new', " .

                "is_hot = '$is_hot', " .

                "is_on_sale = '$is_on_sale', " .

                "is_alone_sale = '$is_alone_sale', " .

                "is_shipping = '$is_shipping', " .

                "goods_desc = '$goods_desc', " .

                "last_update = '". gmtime() ."', ".

                "goods_type = '$goods_type' " .

                "WHERE goods_id = '$_REQUEST[goods_id]' LIMIT 1";

    }

商品详情:
{$FCKeditor}下载远程图片和资源
商品详情:
{$FCKeditor}下载远程图片和资源

 

down.class.php代码:https://pan.baidu.com/s/1rBMZ2COP2i6A37FXo2-DCQ

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值