国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > Wordpress > 正文

WordPress上傳中文附件亂碼解決方法

2024-09-07 00:50:24
字體:
來源:轉載
供稿:網友

中文附件亂碼原因與其它php上傳中文名亂碼原因是一樣的就是編碼問題,因為php對中文支持不怎么樣我可以轉換編碼或直接重命令上傳的文件名即可.

熟悉PHP的朋友可能會很快解決問題,但不熟悉PHP代碼的朋友看過此文章相信一定能解決你的問題,接下來就分享下我的解決wordpress上傳中文文件名亂碼的心得吧~:

找到/wp-admin/includes/file.php這個文件,并最如下修改:

  1. function wp_handle_upload( &$file$overrides = false, $time = null ) { 
  2. //…. 
  3. // Move the file to the uploads dir 
  4. //$new_file = $uploads['path'] . “/$filename”; 
  5. // 修正中文文件名編碼問題 
  6. $new_file = $uploads['path'] . “/” . iconv(“UTF-8″,”GB2312″,$filename); 
  7. //… 
  8. //return apply_filters( ‘wp_handle_upload’, array( ‘file’ => $new_file, ‘url’ => $url, ‘type’ => $type ), ‘upload’ ); 
  9. // 修正中文文件名編碼問題 
  10. return apply_filters( ‘wp_handle_upload’, array( ‘file’ => $uploads['path'] . “/$filename”, ‘url’ => $url, ‘type’ => $type ) , ‘upload’); 

修改完上傳至服務器,問題就解決啦,其實很簡單的啦,簡單的,把以下代碼添加到主題目錄functions.php 文件:

  1. function upload_file($filename) { 
  2. $parts = explode(‘.’, $filename); 
  3. $filename = array_shift($parts); 
  4. $extension = array_pop($parts); 
  5. foreach ( (array$parts as $part
  6. $filename .= ‘.’ . $part
  7. if(preg_match(‘/[一-?]/u’, $filename)){ 
  8. $filename = md5($filename); 
  9. $filename .= ‘.’ . $extension
  10. return $filename ; 
  11. add_filter(‘sanitize_file_name’, ‘upload_file’, 5,1); 

上傳文件自動重命名的方法,下面以wordpress 3.2.1為例,打開wp-admin/includes/file.php文件,找到第326行這段代碼:

  1. // Move the file to the uploads dir 
  2. $new_file = $uploads['path'] . "/$filename"
  3. if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) 
  4.       return $upload_error_handler$file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) ); 

將其修改為:

  1. // Move the file to the uploads dir 
  2. $new_file = $uploads['path'] . "/".date_i18n("YmdHis").floor(microtime()*1000).".".$ext;  
  3. if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) 
  4.         return $upload_error_handler$file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) ); 

保存,重新上傳文件,這樣,新上傳的文件,就會自動保存為“年月日時分秒+千位毫秒整數”的新文件名,并保存到相應的年月文件夾之下了,沒錯,就這么簡單,測試、通過,面對歐美客戶的英文外貿網站推薦使用此法.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临潭县| 临泽县| 宁河县| 清涧县| 台北县| 玉田县| 应用必备| 鸡东县| 榆中县| 濮阳市| 马关县| 翼城县| 曲松县| 年辖:市辖区| 邵东县| 台州市| 迁安市| 施秉县| 驻马店市| 齐齐哈尔市| 门源| 邛崃市| 金门县| 潜江市| 佛教| 吉首市| 虞城县| 铅山县| 梧州市| 拉孜县| 昌吉市| 井陉县| 上林县| 隆回县| 电白县| 涞水县| 云霄县| 瑞昌市| 安宁市| 西吉县| 通道|