WordPress技巧-上传图片自动重命名的几种办法

相关链接

https://zhan.leiue.com/wordpress-rename-images.html

https://zmingcx.com/wordpress-upload-file-renaming.html

关键字:wordpress 上传图片重命名

使用方法

将代码添加到当前主题functions.php模板文件中即可

代码一,按时间重命名

上传文件时会以“年月日时分秒+千位毫秒整数”的格式重命名文件,如“20161023122221765.jpg”

//上传文件重命名
function git_upload_filter($file) {
    $time = date("YmdHis");
    $file['name'] = $time . "" . mt_rand(1, 100) . "." . pathinfo($file['name'], PATHINFO_EXTENSION);
    return $file;
}
add_filter('wp_handle_upload_prefilter', 'git_upload_filter');

代码二,用MD5加密生成数字并重命名

名称规则是由系统自动生成的一个32位的MD5加密文件名,由于默认生成的32位文件名有点长,所以使用substr(md5($name), 0, 20) 截断将其设置为20位

function rename_filename($filename) {
    $info = pathinfo($filename);
    $ext = emptyempty($info['extension']) ? '' : '.' . $info['extension'];
    $name = basename($filename, $ext);
    return substr(md5($name), 0, 20) . $ext;
}
add_filter('sanitize_file_name', 'rename_filename', 10);

其他代码

//根据上传时间重命名文件
add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );
function custom_upload_filter( $file ){
	$info = pathinfo($file['name']);
	$ext = $info['extension'];
	$filedate = date('YmdHis').rand(10,99);//为了避免时间重复,再加一段2位的随机数
	$file['name'] = $filedate.'.'.$ext;
    return $file;
}
//使用md5转码文件名
add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );
function custom_upload_filter( $file ){
	$info = pathinfo($file['name']);
	$ext = '.' . $info['extension'];
	$md5 = md5($file['name']);
    $file['name'] = $md5.$ext;
    return $file;
}

jQuery–检查jquery的版本

想要查看jquery版本号,可以利用jquery属性;jquery属性用于返回jquery版本号。通过想要两种方法来查看jquery版本号

方法1:使用$().jquery

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>	<script> 
	    $(document).ready(function() { 
	            alert("运行的jquery版本是:" + $().jquery); 
	       
	    }); 
	</script>

方法2:使用$.fn.jquery

.jquery 属性是通过 jQuery 原型赋值的,通过使用它的别名 $.fn 进行引用。它是一个含有 jQuery 版本号的字符串,例如 “1.5.0” 或 “1.4.4”.

示例:取得页面上当前使用的 jQuery 的版本号

<script src="https://code.jquery.com/jquery-3.3.1.min.js"> </script>	<script> 
	    $(document).ready(function() { 
	            alert("正在运行的jquery版本:" + $.fn.jquery); 
	       
	    }); 
	</script>

方法3:在jQuery的源代码中查找有关版本好的信息

ZenCart-$db查询之后的数据结构

代码如下

D:\wamp\www\ZenCart\includes\functions\extra_functions\functions_vtscommon.php:56:
class queryFactoryResult#69 (10) {
  public $EOF =>bool(false)
  public $cursor => int(0)
  public $fields =>
  array(8) {
    'products_id' =>
    string(1) "1"
    'products_image' =>
    string(37) "20180420-RB/201804201144211220111.jpg"
    'products_tax_class_id' =>
    string(1) "0"
    'products_name' =>
    string(37) "Ray-Ban Aviator Classic Gold , RB3025"
    'products_date_added' =>
    string(19) "2019-04-24 12:32:17"
    'products_price' =>
    string(8) "203.0000"
    'products_type' =>
    string(1) "1"
    'master_categories_id' =>
    string(1) "1"
  }
  public $is_cached =>
  bool(true)
  public $result =>
  array(6) {
    [0] =>
    array(8) {
      'products_id' =>
      string(1) "1"
      'products_image' =>
      string(37) "20180420-RB/201804201144211220111.jpg"
      'products_tax_class_id' =>
      string(1) "0"
      'products_name' =>
      string(37) "Ray-Ban Aviator Classic Gold , RB3025"
      'products_date_added' =>
      string(19) "2019-04-24 12:32:17"
      'products_price' =>
      string(8) "203.0000"
      'products_type' =>
      string(1) "1"
      'master_categories_id' =>
      string(1) "1"
    }
    [1] =>
    array(8) {
      'products_id' =>
      string(1) "2"
      'products_image' =>
      string(36) "20180420-RB/20180420114420205068.jpg"
      'products_tax_class_id' =>
      string(1) "0"
      'products_name' =>
      string(38) "Ray-Ban Aviator Gradient Gold , RB3025"
      'products_date_added' =>
      string(19) "2019-04-24 12:32:17"
      'products_price' =>
      string(8) "168.0000"
      'products_type' =>
      string(1) "1"
      'master_categories_id' =>
      string(1) "1"
    }
    [2] =>
    array(8) {
      'products_id' =>
      string(1) "3"
      'products_image' =>
      string(36) "20180420-RB/20180420114420901099.jpg"
      'products_tax_class_id' =>
      string(1) "0"
      'products_name' =>
      string(38) "Ray-Ban Aviator Evolve Silver , RB3025"
      'products_date_added' =>
      string(19) "2019-04-24 12:32:17"
      'products_price' =>
      string(8) "183.0000"
      'products_type' =>
      string(1) "1"
      'master_categories_id' =>
      string(1) "1"
    }
    [3] =>
    array(8) {
      'products_id' =>
      string(1) "4"
      'products_image' =>
      string(36) "20180420-RB/20180420114419796045.jpg"
      'products_tax_class_id' =>
      string(1) "0"
      'products_name' =>
      string(33) "Ray-Ban Outdoorsman Gold , RB3030"
      'products_date_added' =>
      string(19) "2019-04-24 12:32:17"
      'products_price' =>
      string(8) "153.0000"
      'products_type' =>
      string(1) "1"
      'master_categories_id' =>
      string(1) "1"
    }
    [4] =>
    array(8) {
      'products_id' =>
      string(1) "5"
      'products_image' =>
      string(37) "20180420-RB/201804201144215330131.jpg"
      'products_tax_class_id' =>
      string(1) "0"
      'products_name' =>
      string(58) "Ray-Ban Outdoorsman Craft Gold ,Polarized Lenses - RB3422Q"
      'products_date_added' =>
      string(19) "2019-04-24 12:32:17"
      'products_price' =>
      string(8) "243.0000"
      'products_type' =>
      string(1) "1"
      'master_categories_id' =>
      string(1) "1"
    }
    [5] =>
    array(8) {
      'products_id' =>
      string(1) "6"
      'products_image' =>
      string(37) "20180420-RB/201804201144210790109.jpg"
      'products_tax_class_id' =>
      string(1) "0"
      'products_name' =>
      string(41) "Ray-Ban Outdoorsman Craft Black , RB3422Q"
      'products_date_added' =>
      string(19) "2019-04-24 12:32:17"
      'products_price' =>
      string(8) "193.0000"
      'products_type' =>
      string(1) "1"
      'master_categories_id' =>
      string(1) "1"
    }
  }
  public $result_random =>
  NULL
  public $limit =>
  int(6)
  public $resource =>
  class mysqli_result#70 (5) {
    public $current_field =>
    int(0)
    public $field_count =>
    int(8)
    public $lengths =>
    array(8) {
      [0] =>
      int(1)
      [1] =>
      int(37)
      [2] =>
      int(1)
      [3] =>
      int(41)
      [4] =>
      int(19)
      [5] =>
      int(8)
      [6] =>
      int(1)
      [7] =>
      int(1)
    }
    public $num_rows =>
    int(6)
    public $type =>
    int(0)
  }
  public $link =>
  class mysqli#7 (19) {
    public $affected_rows =>
    int(6)
    public $client_info =>
    string(79) "mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $"
    public $client_version =>
    int(50011)
    public $connect_errno =>
    int(0)
    public $connect_error =>
    NULL
    public $errno =>
    int(0)
    public $error =>
    string(0) ""
    public $error_list =>
    array(0) {
    }
    public $field_count =>
    int(8)
    public $host_info =>
    string(20) "localhost via TCP/IP"
    public $info =>
    NULL
    public $insert_id =>
    int(0)
    public $server_info =>
    string(6) "5.7.19"
    public $server_version =>
    int(50719)
    public $stat =>
    string(135) "Uptime: 1598  Threads: 1  Questions: 604  Slow queries: 0  Opens: 388  Flush tables: 1  Open tables: 381  Queries per second avg: 0.377"
    public $sqlstate =>
    string(5) "00000"
    public $protocol_version =>
    int(10)
    public $thread_id =>
    int(12)
    public $warning_count =>
    int(0)
  }
  public $sql_query =>
  string(512) "SELECT distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
                           p.products_date_added, p.products_price, p.products_type, p.master_categories_id
                           from products p, products_description pd 
                           where p.products_id = pd.products_id 
                           and pd.language_id = '1' 
                           and p.products_status = 1 and p.products_custom_attributes = 1 order by pd.products_id asc LIMIT 6"
}

ZenCart-memcached使用笔记-配合PHP使用

启动
启动失败原因
需要以管理员的身份运行cmd
C:\memcached-amd64\memcached.exe -m 1024

512表示512M,1024表示1G

配置PHP扩展
使用x86版本哦
D:\wamp\bin\php\php5.6.31\ext\php_memcache.dll

Telnet操作使用因为输入法

C:\memcached-amd64\memcached.exe -d install
C:\memcached-amd64\memcached.exe -d start

命令
stats

ZenCart–覆盖系统 在ZenCart中可以被覆盖重写的地方有哪些?

在ZenCart中可以被覆盖重写的地方有

语言模块

第一处 如果修改english.php的文件
includes/languages/english.php
includes/languages/CUSTOM/english.php

第二处
includes/languages/english/*.php
includes/languages/english/CUSTOM/*.php

第三处
includes/languages/english/html_includes/*.php includes/languages/english/html_includes/CUSTOM/*.php
includes/languages/english/html_includes/responsive_classic/*.php

第四处
includes/languages/english/extra_definitions/*.php
includes/languages/english/extra_definitions/responsive_classic/product_free_shipping.php

还有三个模块
includes/languages/english/modules/order_total
includes/languages/english/modules/payment
includes/languages/english/modules/shipping
以上几个地方 已经将语言部分完全重写了

仔细观察就可以发现,你想修改这些文件,你就需要单独建一个 你主题的文件夹,存放你重写覆盖的文件

模板模块的重写

includes/templates/template_default/templates/*.php
includes/templates/CUSTOM/templates/*.php

includes/modules/sideboxes/*.php
includes/modules/sideboxes/CUSTOM/*.php

includes/modules/*.php
includes/modules/responsive_classic/*.php

以上只是列出了一些,仔细观察,在ZenCart中如果找到带有classic的就表示可以重写

ZenCart-开启关闭gzip,响应头对比,有什么变化

开启Gizip,响应头如下

HTTP/1.1 200 OK
Date: Wed, 25 Dec 2019 02:22:38 GMT
Server: Apache/2.4.41 (Win64) PHP/7.3.12
X-Powered-By: PHP/7.3.12
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Vary: Accept-Encoding
Content-Length: 508
Keep-Alive: timeout=5, max=97
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8


$request_type:NONSSL<br />$PHP_SELF:/ZenCart156cDev/default.php<br />$extra_datafiles_directory:E:/wamp64/www/ZenCart156cDev/includes/extra_datafiles/<br />$ws_extra_datafiles_directory:includes/extra_datafiles/<br />Array
(
    [0] => includes/classes/observers/auto.downloads_via_aws.php
    [1] => includes/classes/observers/auto.downloads_via_redirect.php
    [2] => includes/classes/observers/auto.downloads_via_streaming.php
    [3] => includes/classes/observers/auto.downloads_via_url.php
)
<br />

注意:Vary: Accept-Encoding

关闭之后,响应头如下

HTTP/1.1 200 OK
Date: Wed, 25 Dec 2019 02:19:20 GMT
Server: Apache/2.4.41 (Win64) PHP/7.3.12
X-Powered-By: PHP/7.3.12
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-Length: 508
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8


$request_type:NONSSL<br />$PHP_SELF:/ZenCart156cDev/default.php<br />$extra_datafiles_directory:E:/wamp64/www/ZenCart156cDev/includes/extra_datafiles/<br />$ws_extra_datafiles_directory:includes/extra_datafiles/<br />Array
(
    [0] => includes/classes/observers/auto.downloads_via_aws.php
    [1] => includes/classes/observers/auto.downloads_via_redirect.php
    [2] => includes/classes/observers/auto.downloads_via_streaming.php
    [3] => includes/classes/observers/auto.downloads_via_url.php
)
<br />

ZenCart–采集数据处理流程

采集数据处理流程

web scraper采集字段定义如下:

web-scraper-order,
web-scraper-start-url,
items,
items-href,

pro_name,
pro_new_price,
pro_old_price,
pro_size,

pro_main-src,
pro_des,
pro_detail_img-src,

pro_class,
pro_class_01,
pro_class_02,
pro_class_03

采集下来的数据

命名成1.csv

输入3.2命令 —- 转成1.xls

打开1.xls,删除第一行;替换第二行的“-” 为“_”

输入3.1命令,合并详细图数据 1.xls 生产 1_new.xls

编辑 1_new.xls的数据

–直接生成zencart 的数据 三份

ZenCart156数据上传数据字段定义如下

"v_products_model",
"v_products_type",
"v_products_image",
"v_products_name_1",
"v_products_description_1",
"v_products_url_1",
"v_specials_price",
"v_specials_date_avail",
"v_specials_expires_date",
"v_products_price",
"v_products_weight",
"v_product_is_call",
"v_products_sort_order",
"v_products_quantity_order_min",
"v_products_quantity_order_units",
"v_products_priced_by_attribute",
"v_product_is_always_free_shipping",
"v_date_avail",
"v_date_added",
"v_products_quantity",
"v_manufacturers_name",
"v_categories_name_1",
"v_tax_class_title",
"v_status",
"v_metatags_products_name_status",
"v_metatags_title_status",
"v_metatags_model_status",
"v_metatags_price_status",
"v_metatags_title_tagline_status",
"v_metatags_title_1",
"v_metatags_keywords_1",
"v_metatags_description_1"


"v_products_model",
"v_folder_name",
"v_mainimg",
"v_detailimg",
"v_videosrc",
"v_ext1",
"v_ext2",
"v_ext3"

"v_products_model",
"v_products_options_type",
"v_products_options_name_1",
"v_products_options_values_name_1"

OT数据格式字段定义如下:

Seo标题
Seo关键字
Seo描述
一级分类
二级分类
三级分类
四级分类
产品ID
产品名字
产品原始价格
产品折扣
产品售价
产品型号
产品Sku
产品自定义属性
产品状态
产品排序
产品描述
图片文件夹
主图
详细图
产品相关ID

合并数据之后1_new.xls数据定义字段如下

web_scraper_order
web_scraper_start_url
items
items_href
pro_name
pro_new_price
pro_old_price
pro_size
pro_main_src
pro_des
pro_detail_img_src
pro_class
pro_class_01
pro_class_02
pro_class_03
pro_merge_images