1

I just can't get this to work, basically Im displaying the files on a ftp server, which works fine, but some of the folder names have german characters like ä ö ü or french characters. I placed the line below into the php code to see if it helps but it only gets rid of the french characters, however the german characters still have the � icon instead of the actual character...

header('Content-Type: text/html; charset=utf-8');

I would appreciate any help. Below is the whole file:

import.php

<html>
<head>
    <title>Import</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link type="text/css" rel="stylesheet" href="css/import.css"/>
    <style type="text/css">
        .folder_hilighted table tr td div.name_tag_name{
            background: #75B323;
            color: #ffffff;
            border-radius: 20px;
            text-shadow: 0px -1px 0px #5D855A;
        }
    </style>
</head>
<body><br>
    <table width="100%" cellspacing="0" cellpadding="0"><tr><td>
    <ul class="folders">
    <?php
        ini_set("max_execution_time",100000);
        $folder = $_GET['folder'];

        // set up basic connection
        $ftp_server = "xxx.xxx.xx.xx";
        $ftp_user_name = "admin";
        $ftp_user_pass = "password";

        // set up basic connection
        $conn_id = ftp_connect($ftp_server);

        // login with username and password
        $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

        // get the file list for /
        if($folder==""){
            $buff = ftp_nlist($conn_id, '/array1/MediaBox/iTunes/');
        }
        else{
            $buff = ftp_nlist($conn_id, '/array1/MediaBox/iTunes/'.$folder.'/');
        }

        // close the connection
        ftp_close($conn_id);

        // output the buffer
        for($i=0;$i<=sizeof($buff)-1;$i++){
            if(is_dir('ftp://'.$ftp_user_name.':'.$ftp_user_pass.'@'.$ftp_server.$buff[$i]) && $buff[$i]!="/array1/MediaBox/iTunes/Mobile Applications" && $buff[$i]!="/array1/MediaBox/iTunes/Automatically Add to iTunes.localized" && $buff[$i]!="/array1/MediaBox/iTunes/Books" && $buff[$i]!="/array1/MediaBox/iTunes/Tones"){
                if($folder==""){
                    $folder_name = str_replace(array("/array1/MediaBox/iTunes/"), array(""), $buff[$i]);
                    $folder_name = mb_convert_encoding($folder_name, 'UTF-8', mb_detect_encoding($folder_name));
                    $folder_name = htmlspecialchars($folder_name, ENT_QUOTES, 'UTF-8');
                }
                else{
                    $folder_name = str_replace(array("/array1/MediaBox/iTunes/".$folder."/"), array(""), $buff[$i]);
                    $folder_name = mb_convert_encoding($folder_name, 'UTF-8', mb_detect_encoding($folder_name));
                    $folder_name = htmlspecialchars($folder_name, ENT_QUOTES, 'UTF-8');
                    $last_folder = str_replace(array("/array1/MediaBox/iTunes/"), array(""), $buff[$i]);
                    $last_folders = explode("/", $last_folder);
                    for($k=0;$k<=count($last_folders);$k++){
                        if($k==count($last_folders)){
                            $prev_folder = $last_folders[$k-3];
                        }
                    }
                }
            ?>
                <li align="center" title="<?php echo $folder_name ?>" id="<?php echo md5($folder_name); ?>"  onClick="hilight_folder('<?php echo md5($folder_name); ?>');" ondblclick="change_folder('<?php echo $folder_name; ?>')" style="cursor: pointer; height: 90px;">
                    <table cellspacing="0" cellpadding="0">
                        <tr>
                            <td align="center">
                                <img height="75" style="padding-left: 5px; padding-right: 5px; padding-top: 5px;" src="img/folder.png">
                                <div class="prev_folder" style="display: none;"><?php echo $prev_folder ?></div>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" class="name_tag">
                                <div class="name_tag_name" style="margin-top: 2px; width: auto;">
                                    <?php
                                        $short_folder = substr($folder_name, 0, 12); 
                                        if($folder_name == $short_folder){

                                        }
                                        else{
                                            $short_folder = $short_folder."...";
                                        }
                                        echo $short_folder;
                                    ?>
                                </td>
                            </div>
                        </tr>
                    </table>
                </li>
            <?php
            }
            else if($buff[$i]!="/array1/MediaBox/iTunes/Mobile Applications" && $buff[$i]!="/array1/MediaBox/iTunes/Automatically Add to iTunes.localized" && $buff[$i]!="/array1/MediaBox/iTunes/Books" && $buff[$i]!="/array1/MediaBox/iTunes/Tones" && $buff[$i]!="/array1/MediaBox/iTunes/" && $buff[$i]!="/array1/MediaBox/iTunes/Icon"){
                if($folder==""){
                    $folder_name = str_replace(array("/array1/MediaBox/iTunes/"), array(""), $buff[$i]);
                }
                else{
                    $folder_name = str_replace(array("/array1/MediaBox/iTunes/".$folder."/"), array(""), $buff[$i]);
                    $last_folder = str_replace(array("/array1/MediaBox/iTunes/"), array(""), $buff[$i]);
                    $last_folders = explode("/", $last_folder);
                    for($k=0;$k<=count($last_folders);$k++){
                        if($k==count($last_folders)){
                            $prev_folder = $last_folders[$k-3];
                        }
                    }
                }
                ?>
                    <li align="center" title="<?php echo $folder_name ?>" id="<?php echo md5($folder_name); ?>"  onClick="hilight_folder('<?php echo md5($folder_name); ?>');" ondblclick="change_folder('<?php echo str_replace(array("/array1/MediaBox/iTunes/"), array(""), $buff[$i]); ?>')" style="cursor: pointer; height: 90px;">
                        <table cellspacing="0" cellpadding="0">
                            <tr>
                                <td align="center">
                                    <img height="75" style="padding-left: 5px; padding-right: 5px; padding-top: 5px;" src="img/music_file.png">
                                    <div class="prev_folder" style="display: none;"><?php echo $prev_folder ?></div>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" class="name_tag">
                                    <div class="name_tag_name" style="margin-top: 2px; width: auto;">
                                        <?php
                                            $short_folder = substr($folder_name, 0, 12); 
                                            if($folder_name == $short_folder){

                                            }
                                            else{
                                                $short_folder = $short_folder."...";
                                            }
                                            echo $short_folder;
                                        ?>
                                    </td>
                                </div>
                            </tr>
                        </table>
                    </li>
                <?php
            }
        }
        ftp_close($conn_id);
    ?>
    </ul>
</td></tr>
<tr><td>
    <div style="height: 60px;">&nbsp;</div>
</td></tr></table>
</body>
</html>

2 Answers 2

3

If it's possible (if it is supported on FTP server) try to call:

ftp_raw($conn_id, "OPTS UTF8 ON");

This command enable UTF-8 encoding for directory listing (ftp_nlist).

Sign up to request clarification or add additional context in comments.

Comments

0

Okay, I've worked out a work around which may be useful for other people to know:

str_replace(array('%82','%94','+'),array('&#233;','&#246;',' '),urlencode($folder_name));

It's not the best way, but it works for me, if you url encode a string it changes the awkward characters into e.g. %82... You can then replace these with the HTML codes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.