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

本文主要是介绍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

 

这篇关于ecshop编辑商品,远程图片自动本地化插件,自动上传外链图片的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1044876

相关文章

Python脚本实现自动删除C盘临时文件夹

《Python脚本实现自动删除C盘临时文件夹》在日常使用电脑的过程中,临时文件夹往往会积累大量的无用数据,占用宝贵的磁盘空间,下面我们就来看看Python如何通过脚本实现自动删除C盘临时文件夹吧... 目录一、准备工作二、python脚本编写三、脚本解析四、运行脚本五、案例演示六、注意事项七、总结在日常使用

C#中图片如何自适应pictureBox大小

《C#中图片如何自适应pictureBox大小》文章描述了如何在C#中实现图片自适应pictureBox大小,并展示修改前后的效果,修改步骤包括两步,作者分享了个人经验,希望对大家有所帮助... 目录C#图片自适应pictureBox大小编程修改步骤总结C#图片自适应pictureBox大小上图中“z轴

使用Python将长图片分割为若干张小图片

《使用Python将长图片分割为若干张小图片》这篇文章主要为大家详细介绍了如何使用Python将长图片分割为若干张小图片,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. python需求的任务2. Python代码的实现3. 代码修改的位置4. 运行结果1. Python需求

SpringBoot项目启动后自动加载系统配置的多种实现方式

《SpringBoot项目启动后自动加载系统配置的多种实现方式》:本文主要介绍SpringBoot项目启动后自动加载系统配置的多种实现方式,并通过代码示例讲解的非常详细,对大家的学习或工作有一定的... 目录1. 使用 CommandLineRunner实现方式:2. 使用 ApplicationRunne

Java文件上传的多种实现方式

《Java文件上传的多种实现方式》文章主要介绍了文件上传接收接口的使用方法,包括获取文件信息、创建文件夹、保存文件到本地的两种方法,以及如何使用Postman进行接口调用... 目录Java文件上传的多方式1.文件上传接收文件接口2.接口主要内容部分3.postman接口调用总结Java文件上传的多方式1

Xshell远程连接失败以及解决方案

《Xshell远程连接失败以及解决方案》本文介绍了在Windows11家庭版和CentOS系统中解决Xshell无法连接远程服务器问题的步骤,在Windows11家庭版中,需要通过设置添加SSH功能并... 目录一.问题描述二.原因分析及解决办法2.1添加ssh功能2.2 在Windows中开启ssh服务2

Springboot的ThreadPoolTaskScheduler线程池轻松搞定15分钟不操作自动取消订单

《Springboot的ThreadPoolTaskScheduler线程池轻松搞定15分钟不操作自动取消订单》:本文主要介绍Springboot的ThreadPoolTaskScheduler线... 目录ThreadPoolTaskScheduler线程池实现15分钟不操作自动取消订单概要1,创建订单后

使用Python实现大文件切片上传及断点续传的方法

《使用Python实现大文件切片上传及断点续传的方法》本文介绍了使用Python实现大文件切片上传及断点续传的方法,包括功能模块划分(获取上传文件接口状态、临时文件夹状态信息、切片上传、切片合并)、整... 目录概要整体架构流程技术细节获取上传文件状态接口获取临时文件夹状态信息接口切片上传功能文件合并功能小

python实现自动登录12306自动抢票功能

《python实现自动登录12306自动抢票功能》随着互联网技术的发展,越来越多的人选择通过网络平台购票,特别是在中国,12306作为官方火车票预订平台,承担了巨大的访问量,对于热门线路或者节假日出行... 目录一、遇到的问题?二、改进三、进阶–展望总结一、遇到的问题?1.url-正确的表头:就是首先ur

Spring使用@Retryable实现自动重试机制

《Spring使用@Retryable实现自动重试机制》在微服务架构中,服务之间的调用可能会因为一些暂时性的错误而失败,例如网络波动、数据库连接超时或第三方服务不可用等,在本文中,我们将介绍如何在Sp... 目录引言1. 什么是 @Retryable?2. 如何在 Spring 中使用 @Retryable