在以前我記得分享一篇在上傳文件時按日期自動生成一個名字,這樣可以防止有重復的文件名替換了,下面我今天再分享一個差不多功能的處理方法:
打開“wp-admin/includes/file.php”文件,找到第313行和452行這段代碼:
- $new_file = $uploads['path'] . "/$filename"; //主要是修改這行的代碼!
- if ( false === @ rename( $file['tmp_name'], $new_file ) ) {
- if ( 0 === strpos( $uploads['basedir'], ABSPATH ) )
- $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
- else
- $error_path = basename( $uploads['basedir'] ) . $uploads['subdir'];
- return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $error_path ) );
- }
把上面代碼改成如下代碼:
新聞熱點
疑難解答
圖片精選