PHP中FCK上傳圖片檔案名稱亂碼_PHP教程

來源:互聯網
上載者:User
使用fck的朋友可能會碰這樣一個情況就是如果上你的檔案名稱為英文字母是沒有任何問題,如果上傳的是中文漢字就會出現中文名亂碼了,下面我來給大家分析與介紹解決方案。

主要原因是fck中的編(utf-8)碼和本地的編碼(gbk)環緊不一致導致的,修改如下5個檔案可以解決

更改FileUpLoad函數 ckeditor/" target="_blank">fckeditoreditorfilemanagerconnectorsphpcommands.php

在檔案中找到以下代碼:

代碼如下 複製代碼

// Get the extension.
$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
$sExtension = strtolower( $sExtension ) ;

在其後加上一句:

代碼如下 複製代碼

$sFileName = strtotime('now').'.'.$sExtension;

這樣檔案名稱就是 目前時間戳+尾碼名了。既解決了中文亂碼,也解決了檔案重名

另一種解決辦法,保留中文名

檔案4:fckeditoreditorfilemanagerconnectorsphpcommands.php

找到

代碼如下 複製代碼

function FileUpload( $resourceType, $currentFolder, $sCommand ){

。。。

找到

//move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;

move_uploaded_file( $oFile['tmp_name'], iconv("utf-8","gbk",$sFilePath));

}

對檔案名稱$sFilePath轉碼。

檔案5:fckeditoreditorfilemanagerconnectorsphputil.php

找到

代碼如下 複製代碼

function ConvertToXmlAttribute( $value ){

。。。

找到

//return ( utf8_encode( htmlspecialchars( $value ) ) ) ;

return iconv("GBK", "UTF-8", htmlspecialchars( $value ));

}

對內容進行轉碼。

http://www.bkjia.com/PHPjc/632133.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632133.htmlTechArticle使用fck的朋友可能會碰這樣一個情況就是如果上你的檔案名稱為英文字母是沒有任何問題,如果上傳的是中文漢字就會出現中文名亂碼了,下...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.