Jump to content

PHP FTP_GET - Can't handle special characters


kool_samule

Recommended Posts

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

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.