0

これは、私を別の ftp サーバーに接続し、その内容を表示する私の php コードです。次に、結果をテーブルに入れます。ただし、3 エントリごとにテーブルに新しいタグを作成する必要があります。私は次のことを試しました:

<html>
<head><title>some crap</title>
<style type="text/css">
<!--
@import url("style.css");
-->
</style>
</head>
<body>
<table id="gradient-style">
    <thead>
        <tr>
            <th colspan='99'>folders</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <td colspan='99'>End</td>
        </tr>
    </tfoot>
    <tbody>
    <tr>
<td>
<?php
$ftpHost = 'xxx';
$ftpUser = 'xxx';
$ftpPass = 'xxx';
$startDir = 'logs';
$n = 0;

if (isset($_GET['file'])) {
    // Get file contents (can also be fetched with cURL)
    $contents = file_get_contents("ftp://$ftpUser:$ftpPass@$ftpHost/$startDir/" . urldecode($_GET['file']));

    // Get mime type (requires PHP 5.3+)
    $finfo = new finfo(FILEINFO_MIME);
    $mimeType = $finfo->buffer($contents);

    // Set content type header and output file
    header("Content-type: $mimeType");
    echo $contents;
}
else {
    $dir = (isset($_GET['dir'])) ? $_GET['dir'] : '';

    $conn = ftp_connect($ftpHost) or die("Could not connect, please refresh in 2 seconds");
    ftp_login($conn, $ftpUser, $ftpPass);

    // change dir to avoid ftp_rawlist bug for directory names with spaces in them
    ftp_chdir($conn, "$startDir/$dir");

    // fetch the raw list
    $list = ftp_rawlist($conn, '');
    reset($list);

    while (list(, $item) = each($list)) {
        if(!empty($item)) {
            // Split raw result into pieces
            $pieces = preg_split("/[\s]+/", $item, 9);

            // Get item name
            $name = $pieces[8];

            // Skip parent and current dots
            if ($name == '.' || $name == '..' || $name == 'index.html')
                continue;
            if($n%3 == 0){echo "<tr>";}
            // Is directory
            if ($pieces[0]{0} == 'd') {
                echo "<a href='?dir={$dir}/{$name}'><strong>{$name}</strong></a><td>";
            }
            // Is file
            else {
                echo "<a href='displayer.php?file={$dir}/{$name}'>{$name}</a><td>";
            }
            $n++;
            }
        }
    }
    ftp_close($conn);
?>
    </tr>
    </tbody>
</table>
</body>
</html>

しかし、奇妙な結果が表示されます ここをクリックして私のページを確認してください
私のコードで何が間違っているようですか?

4

1 に答える 1

1

私が見る限り、あなたは間違ったマークアップを持っています。エコーする各結果に始まりと終わりがあることを確認してください:

// Is directory
            if ($pieces[0]{0} == 'd') {
                echo "<td><a href='?dir={$dir}/{$name}'><strong>{$name}</strong></a></td>";
            }
            // Is file
            else {
                echo "<td><a href='displayer.php?file={$dir}/{$name}'>{$name}</a></td>";
            }
于 2012-10-18T19:43:59.583 に答える