Php 如果目录为空,如何使目录列表文本消失
我对当前用于显示目录文件内容的php代码很满意,但它当前显示的是“文件列表”,我想知道如果目录为空,如何使该文本消失,如果可能的话。我目前使用的代码如下:Php 如果目录为空,如何使目录列表文本消失,php,directory,directory-listing,Php,Directory,Directory Listing,我对当前用于显示目录文件内容的php代码很满意,但它当前显示的是“文件列表”,我想知道如果目录为空,如何使该文本消失,如果可能的话。我目前使用的代码如下: <?php if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $thelist .= '<a
<?php
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$thelist .= '<a href="'.$file.'">'.$file.'</a>';
}
}
closedir($handle);
}
?>
<P>List of files:</p>
<P><?=$thelist?></p>
文件列表:
非常感谢您的帮助。请在最后一部分添加一个条件:
<?php if (!empty($thelist)) { ?>
<P>List of files:</p>
<P><?=$thelist?></p>
<?php } ?>
文件列表:
试试这个:
<?php
if ( $handle = opendir('.')) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( $file != "." && $file != ".." ) {
$thelist .= "<a href=\"".$file."\">".$file."</a><br />";
}
}
}
closedir( $handle );
if ( strlen( $thelist ) > 0 ) {
echo "<p>List of files:</p>";
}
?>
<p><?=$thelist?></p>
echo设置($t列表)$列表:'';