WordPress 上传媒体库文件重命名 全格式支持

修改上传文件名为:年月日时分秒+两位随机数.扩展名
打开/wp-admin/includes/file.php文件

  1. $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );  
  2.   
  3. // Move the file to the uploads dir.  

替换为

  1. $time=date("YmdH:i:s",time()+8*60*60);  
  2. $file['name'] = $time."".mt_rand(1,100).".".$ext ;  
  3. $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );  
  4.   
  5. // Move the file to the uploads dir.  

保存覆盖源文件即可!

shashou47

发表评论取消回复

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:1   其中:访客  1   博主  0

    • avatar muse 0

      请问怎么反过来修改呢?我现在上传到媒体库的文件都是以时间作为文件名的,而改变了原来的文件名,请问是不是wordpress版本更新的原因呢?所有主题都是这样,我去file.php下看了,还是$filename = wp_unique_filename( $uploads[‘path’], $file[‘name’], $unique_filename_callback ); 并没有变化