但在开发过程中发现,最新版本的wordpress 3,中文名的图片上传以后,会出现乱码的现象(记得2.7的版本好像没有这个问题),总不能让客户自己改为英文文件名再上传吧(虽然这样做比较迎合搜索引擎)。那只好按照中国cms的惯例,上传文件,自动按年月日来重命名了,另一方面来说这样也方便管理。
但是上百度、google一搜,居然没有相关内容,可能是太简单了吧,高手都不屑于写解决方法。好吧,那就动动爪子自己研究研究吧。
下面以wordpress 3.2.1为例,打开wp-admin/includes/file.php文件,找到第326行这段代码:
// 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_i18n("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'] ) );
保存,重新上传文件。这样,新上传的文件,就会自动保存为“年月日时分秒+千位毫秒整数”的新文件名,并保存到相应的年月文件夹之下了。没错,就这么简单,测试、通过。面对欧美客户的英文外贸网站推荐使用此法。
当然,也可以百度一下修正“wordpress 上传中文文件乱码”的方法,让wp3直接支持中文文件名,中文网站可以一试。
http://wlwl.co/news/20111214167.html