实现wordpress上传文件自动重命名
技巧资源

实现wordpress上传文件自动重命名

废话不多说直接说: 在wordpress程序的wp-admin/includes/目录中找到file.php文件,并进行编辑,在329行到332行中(我的是wordpress 3.5英文版)会看到以下代码: [php] // 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'] ) ); [/php] 将其替换为: [php] // 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'] ) ); [/php] 上文中红色的“YmdHis”就是上传后修改成的时间“年月日时分秒” 参考网站:点击进入