PHP - Handling UTF-8 Filenames
The challenge presented here involves uploading a file with a UTF-8 filename, such as "Tên Tệp Tiếng Việt.JPG," but encountering a display issue where the filename is garbled with special characters on the local computer.
The provided code lacks the necessary conversion to support UTF-8 filenames in the Windows environment. To address this, the following strategies can be considered:
Option 1: Converting Filename to System Code Page (cp1258)
The following code can be used:
<code class="php">$base_dir = "D:/"; $fn = $_FILES["upload"]["name"]; $fn2 = iconv("UTF-8","cp1258", $base_dir.$fn);</code>
Option 2: Changing System Code Page to Vietnamese
Limitations and Considerations:
The above is the detailed content of How to Handle UTF-8 Filenames in PHP on Windows?. For more information, please follow other related articles on the PHP Chinese website!