」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 如何處理PHP文件系統功能中的UTF-8文件名?

如何處理PHP文件系統功能中的UTF-8文件名?

發佈於2025-04-13
瀏覽:971

How Can I Handle UTF-8 Filenames in PHP's Filesystem Functions?
在PHP的Filesystem functions中處理UTF-8 FileNames

在使用PHP的MKDIR函數中含有UTF-8字符的文件很多flusf-8字符時,您可能會在Windows Explorer中遇到comploreer grounder grounder grounder grounder jorpodibibors.unsunsibors。 URL編碼FILENAMES

來解決此問題,請使用urlencode函數將所需的文件夾名稱轉換為URL-SAFE格式,然後再將其傳遞給mkdir:這確保文件夾名稱中的所有字符均已編碼為所有操作系統的有效文件名。要檢索原始的UTF-8文件名,請使用uroldecode。

替代解決方案(帶有警告)

Restrict to ISO-8859-1 Characters

Alternatively, limit filenames to characters representable in ISO-8859-1. Use utf8_decode and utf8_encode to convert filenames between UTF-8 and ISO-8859-1.

However, these alternatives come with caveats:
$dir_name = urlencode("Depósito");
mkdir($dir_name);

Filesystem functions cannot handle bytes that match invalid Windows filesystem characters in ISO-8859-1.

Windows may use非英語環境中的非ISO-8859-1編碼,需要更複雜的轉換。

最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3