kool_samule Posted March 15, 2010 Share Posted March 15, 2010 Hi Chaps, I have a PHP FTP app where users can up/download files. Our company deals with foreign languages, so some of the files may have special characters, such as (German) umlauts. Uploading files with umlauts seems fine, but when I download a file, it goes from: Häuse.pdf to Häuse.pdf Is there any way to get round this, so it keeps the correct file name? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/195289-php-ftp_get-cant-handle-special-characters/ Share on other sites More sharing options...
FD_F Posted March 15, 2010 Share Posted March 15, 2010 try work with UTF-8 example: header('Content-type: text/html; charset=UTF-8') ; Quote Link to comment https://forums.phpfreaks.com/topic/195289-php-ftp_get-cant-handle-special-characters/#findComment-1026304 Share on other sites More sharing options...
kool_samule Posted March 15, 2010 Author Share Posted March 15, 2010 Hi, thanks for the reply, sorry if this is a stupid question but where would I set UTF-8, I have a form where users can select a file to upload, which is posted to a script page, which does the work. So is it the select (form) or script page that needs to be told to use UTF-8? Quote Link to comment https://forums.phpfreaks.com/topic/195289-php-ftp_get-cant-handle-special-characters/#findComment-1026324 Share on other sites More sharing options...
Adam Posted March 15, 2010 Share Posted March 15, 2010 Most likely your "FTP app" doesn't support that character set. Is it a known client or your own custom made? Quote Link to comment https://forums.phpfreaks.com/topic/195289-php-ftp_get-cant-handle-special-characters/#findComment-1026325 Share on other sites More sharing options...
kool_samule Posted March 15, 2010 Author Share Posted March 15, 2010 it's a custom made PHP based FTP client. Quote Link to comment https://forums.phpfreaks.com/topic/195289-php-ftp_get-cant-handle-special-characters/#findComment-1026327 Share on other sites More sharing options...
kool_samule Posted March 15, 2010 Author Share Posted March 15, 2010 OK, I've got the upload function working correctly now, using: $raw_file = $x function FixEncoding($raw_file){ if(mb_detect_encoding($raw_file)=='UTF-8'){ return $raw_file; }else{ return utf8_decode($raw_file); } } $file = utf8_decode($raw_file); ...which works for a file a sinlge file ($x), passed from a form. I have a ftp_nlist array which I need to convert to UTF-8, so that the disply list and download links work correctly. . . . This is my table so far: <table border="0" cellpadding="0" cellspacing="0" id="tbldisplay"> <tr> <th>Type</th> <th>Title</th> <th>Open</th> <th>Download</th> <th>Delete</th> </tr> <?php $ftp_nlist = ftp_nlist($conn, "."); //alphabetical sorting sort($ftp_nlist); foreach ($ftp_nlist as $value) { //1. Size is '-1' => directory if (ftp_size($conn, $value) == -1) { //output as [ directory ]?> <tr> <td><img src="images/folder.png" /></td> <td><?php echo $value;?></td> <td><a href="<?php $_SERVER['PHP_SELF']?>?dir=<?php echo $ftpPath.'/'.$value ;?>"><img src="images/open_folder.png" width="20" height="20" border="0" /></a></td> <td>---</td> <td><a href="ftp_dir_delete.php?dir=<?php echo $ftpPath;?>&delete_dir=<?php echo $value ;?>"><img src="images/delete2.png" border="0"/></a></td> </tr> <?php } } foreach ($ftp_nlist as $value) { //2. Size is not '-1' => file if (!(ftp_size($conn, $value) == -1)) { //output as file?> <tr> <td><img src="images/file.png" /></td> <td><?php echo $value;?></td> <td>---</td> <td><a href="ftp_file_download_select.php?dir=<?php echo $ftpPath;?>&file=<?php echo $value ;?>"><img src="images/download.png" border="0"/></a></td> <td><a href="ftp_file_delete.php?dir=<?php echo $ftpPath;?>&file=<?php echo $value ;?>"><img src="images/delete2.png" border="0"/></a></td> </tr> <?php } } ?> </table> If someone can help me get the values of the ftp_nlist through the encoding function to display the correct filenames, that would be ultra-sweet Quote Link to comment https://forums.phpfreaks.com/topic/195289-php-ftp_get-cant-handle-special-characters/#findComment-1026427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.