我只是无法让它工作,基本上我在 ftp 服务器上显示文件,这工作正常,但一些文件夹名称有德语字符,如 ä ö ü 或法语字符。我将下面的行放入 php 代码中,看看它是否有帮助,但它只去掉了法语字符,但是德语字符仍然有 � 图标而不是实际字符...
header('Content-Type: text/html; charset=utf-8');
我将不胜感激任何帮助。以下是整个文件:
导入.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;"> </div>
</td></tr></table>
</body>
</html>