How can the use of utf8 filenames impact the retrieval of files from FTP URLs in PHP?
When dealing with UTF-8 filenames in FTP URLs in PHP, it's important to ensure that the filenames are properly encoded and decoded to prevent any issues with file retrieval. One common approach is to use the `rawurlencode()` function to encode the filenames before using them in FTP URLs, and then use `urldecode()` to decode them when retrieving the files.
// Encode UTF-8 filename for FTP URL
$filename = '文件.txt';
$encodedFilename = rawurlencode($filename);
// FTP URL with encoded filename
$ftpUrl = 'ftp://username:password@ftp.example.com/' . $encodedFilename;
// Retrieve file using encoded filename
$fileContent = file_get_contents($ftpUrl);
// Decode filename after retrieval
$decodedFilename = urldecode($encodedFilename);
echo $fileContent;
echo $decodedFilename;