In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how WordPress can automatically rename uploaded files. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Code 1, rename by time
When uploading a file, the file is renamed in the format of "year, month, day, hour, second + kilobit millisecond integer", such as "20161023122221765.jpg"
/ / upload file rename 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')
Source code:
Http://www.lmlblog.com/2147.html
Code 2, use MD5 encryption to generate numbers and rename them
The name rule is a 32-bit MD5 encrypted file name automatically generated by the system. Because the default generated 32-bit file name is a bit long, it is set to 20 bits using substr (md5 ($name), 0,20) truncation.
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)
Source code:
Http://www.boke8.net/wordpress-auto-rename-file.html
Usage
Just add the code to the current theme functions.php template file.
About WordPress how to achieve automatic renaming of uploaded files to share here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.