WordPress上传文件默认是不改变文件名称的,可对中文文件名而言,某些系统、某些浏览器访问是会出现问题滴,那么怎样让Wordpress上传文件自动重命名呐?
以wordpress 3.5.1为例,打开“wp-admin/includes/file.php”文件,找到第327行这段代码:
// Move the file to the uploads dir $new_file = $uploads['path'] . "/$filename"; if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
将其修改为
// Move the file to the uploads dir $new_file = $uploads['path'] . "/".date("YmdHis").floor(microtime()*1000).".".$ext; if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
保存,重新上传文件。这样,新上传的文件,就会自动保存为“年月日时分秒+千位毫秒整数”的新文件名,并保存到相应的年月文件夹之下了。
原文地址:http://www.teanie.com/let-wordpress-upload-files-to-be-automatic-rename.html
from www.waitalone.cn.thanks for it.
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论