0
이것은 나를 다른 ftp 서버와 연결하고 그 내용을 보여주는 내 PHP 코드입니다. 그런 다음 결과를 테이블에 넣습니다. 그러나 매 3 번째 엔트리마다 테이블에 새로운 태그를 생성하고 싶습니다.내용의 수에 따라 동적 테이블 raws
<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:[email protected]$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>
하지만 난 내 코드에서 잘못된 것 같다 무슨 이상한 결과 click here to see my page
를 얻을 : 나는 다음과 같은 시도 했습니까?
// 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>";
}
: