<?php
$handle=opendir('.');
echo "目录 handle: $handle\n";
echo "档案:\n";
while ($file = readdir($handle)) {
   if(eregi("[_\.0-9a-z-]+[\.]+gif$",$file))
    echo "<img src=$file\n width=100 height=100>";
}
closedir($handle); 
?>

解决方案 »

  1.   

    能再问个初级的问题吗?我如果想使用表格的形式来显示图片的话
    怎么根据图片的数量来生成表格的多少啊
    我才开始看PHP
    请指教
    分数可以再加
      

  2.   

    <table width="90%" border="0" cellspacing="0" cellpadding="0">
      <tr> 
    <?php
    $handle=opendir('.');
    echo "目录 handle: $handle\n";
    echo "档案:\n";
    $rows=0;
    while ($file = readdir($handle)) {
       if(eregi("[_\.0-9a-z-]+[\.]+gif$",$file)) $rows++;//取得图片的总数
    }
    $n=0;
    while ($file = readdir($handle)) {
       if(eregi("[_\.0-9a-z-]+[\.]+gif$",$file))    echo "<td><table width='100%' border='0' cellspacing='0' cellpadding='0'>
                  <tr>
                   <td><div align='center'><img src=$file\n width=100 height=100></div></td>//输出图片
                  </tr>
                  <tr>
                    <td>".$file."</td>//输出文件名
                  </tr>
                 </table></td>";
         if($rows==0) echo "</tr>";
         $rows--;
         $n++;
         if($n==4)//$n==4,指定一行显示4张图片,也可以设为其他大于0 的数值
           {
             echo "</tr>";
             $n=0;
           }
        echo "<img src=$file\n width=100 height=100>";
    }
    closedir($handle); 
    ?>
      </tr>
    </table>
      

  3.   

    删除上面回复中倒数第6行的:
    echo "<img src=$file\n width=100 height=100>";
      

  4.   

    删除上面回复倒数第6行(echo "<img src=$file\n width=100 height=100>";
      

  5.   

    <html>
    <head>
    <title>精彩照片区</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link rel="stylesheet" href="css/guessbook.css" type="text/css">
    </head><body bgcolor="#FFFFFF" text="#000000">
    <?
    include "util/img_ctrl.php";
    include "util/utils.php";

    $RootDir = "g:\\mySite"; //网站所在路径
    $PhotoDir = "myphoto"; //图片所在路径
    $BaseDir = $RootDir . "\\" . $PhotoDir; //基路径

    $PieceOfLine = 3; //每行多少张照片

    $d = dir($BaseDir); //取基路径下的目录
    //并取得目录描述
    $fp = fopen($BaseDir . "\\dirinfo.txt", "r"); $i = 0;
    while (!feof($fp))
    {
    while($Dir[$i] = trim(fgets($fp, 4096)))
    {
    $DirInfo[$i] = fgets($fp, 4096);
    break;
    }
    $i++;
    }
    fclose($fp);

    //取当前希望进的路径
    $CurDir = $_GET["dir"];
    if ($CurDir == "")
    {
    $CurDir = count($Dir) - 1;
    } $TargetDir = $BaseDir . "\\" . $Dir[$CurDir];
    $LinkDir = "/" . $PhotoDir . "/" . $Dir[$CurDir]; $d = dir($TargetDir);
    $i = 0;
    while ($entry = $d->read())
    {
    if($entry != "." && $entry != ".." && strtoupper($entry) != "COMMENT.TXT" && strtoupper($entry) != "COMMENT.TXT.BAK" && strtoupper($entry) != "THUMB")
    {
    $FileName[$i] = $entry;
    $Pic[$i] = new JpegPic($TargetDir . "\\" . $entry);
    $Pic[$i]->saveThumb($TargetDir . "\\thumb\\TN_" . $entry); //取得照片介绍
    $fp = fopen($TargetDir . "\\comment.txt", "r");
    if ($fp)
    {
         while($buffer = fgets($fp, 4096))
         {
         if (trim(strtoupper($buffer)) == strtoupper($entry))
         {
         $Content[$i] = fgets($fp, 4096);
         break;
         }
         }
    }
        fclose($fp);

    $i++;
    }
    }
    $d->close(); $Lines = (int)(count($FileName) / $PieceOfLine); //整3张的行数
    $Mod   = (int)(count($FileName) % $PieceOfLine); //最后一张的“零头”数
    ?>
    <table width="720" border="0" align="center">
      <tr>
        <td class="guestbool_title">
          <div align="center">精 彩 照 片 区</div>
        </td>
      </tr>
    </table>
    <br>
    <table width="720" border="0" align="center" height="224" class="content">
      <tr> 
        <td rowspan=<?=$Lines+1?> width="161" valign="top" height="180"> 
          <table width="158" border="0" align="center" class="content" cellspacing="0" cellpadding="5">
            <?
    for($i = count($Dir) - 1; $i >= 0; $i--)
    {
             echo "<tr>\n";
               echo " <td>\n";
               if ($CurDir == $i)
                 echo " <div align='center'><a href='photo.php?dir=" . $i . "'>&gt;&gt; " . $DirInfo[$i] . " &lt;&lt;</a></div>\n";
               else
                 echo " <div align='center'><a href='photo.php?dir=" . $i . "'>" . $DirInfo[$i] . "</a></div>\n";
               echo " </td>\n";
             echo "</tr>\n";
            }
    ?>
          </table>
        </td>
        <?
    if (count($FileName) == 0)
    {
    //没有照片的处理
    echo "<td width='500' height='200'><div align='center'><b>[此分类暂时还没有照片]</b></div></td>";
    }
    for($i = 0; $i < $Lines; $i++)
    {
    if ($i > 0) echo "<tr>\n"; //第一行不加<tr>,如果不是第一行,则加上

    for($j = 0; $j < $PieceOfLine; $j++)
    {
    ?>
        <td width="180" height="180"> 
          <table width="160" border="0" align="center" height="212" class="content">
            <tr> 
              <td height="160"> 
                <?
                 $linktarget = $LinkDir . "/" . $FileName[$i * $PieceOfLine + $j];
                 $thumbtarget = $LinkDir . "/thumb/TN_" . $FileName[$i * $PieceOfLine + $j];
                
                 echo "<div align='center'><a href='" . $linktarget . "' target='_blank'><img src='" . $thumbtarget . "' border='0' alt='" . $Content[$i * $PieceOfLine + $j] . "'></a></div>";
    ?>
              </td>
            </tr>
            <tr> 
              <td height="2"> 
                <div align="center"> 
                  <?
                   if ($Content[$Lines * $PieceOfLine + $i] != "")
                   echo $Content[$i * $PieceOfLine + $j] . "<br>\n";
                   else
                   echo $FileName[$i * $PieceOfLine + $j] . "<br>\n";
                  
                   echo $Pic[$i * $PieceOfLine + $j]->getWidth() . "x" . $Pic[$i * $PieceOfLine + $j]->getHeight() . "<br>\n";
                   echo utils::comma_num($Pic[$i * $PieceOfLine + $j]->GetFileSize()) . "字节"
                   ?>
                </div>
              </td>
            </tr>
          </table>
        </td>
        <?
    } // end for j
    echo "</tr>\n";
    } //end for i //处理“零头”
    if ($Lines > 0)  echo "<tr>\n"; //第一行不加<tr>,如果不是第一行,则加上
    for($i = 0; $i < $Mod; $i++)
    {
    ?>
        <td width="184" height="180"> 
          <table width="156" border="0" align="center" height="212" class="content">
            <tr> 
              <td height="167"> 
                <?
    $linktarget = $LinkDir . "/" . $FileName[$Lines * $PieceOfLine + $i];
    $thumbtarget = $LinkDir . "/thumb/TN_" . $FileName[$Lines * $PieceOfLine + $i];
    //echo $thumbtarget;
                 echo "<div align='center'><a href='" . $linktarget . "' target='_blank'><img src='" . $thumbtarget . "' border='0' alt='" . $Content[$Lines * $PieceOfLine + $i] . "'></a></div>";
    ?>
              </td>
            </tr>
            <tr> 
              <td height="2"> 
                <div align="center"> 
                  <?
                   if ($Content[$Lines * $PieceOfLine + $i] != "")
                   echo $Content[$Lines * $PieceOfLine + $i] . "<br>\n";
                   else
                   echo $FileName[$Lines * $PieceOfLine + $i] . "<br>\n";
                  
                   echo $Pic[$i * $PieceOfLine + $j]->getWidth() . "x" . $Pic[$i * $PieceOfLine + $j]->getHeight() . "<br>\n";
                   echo utils::comma_num($Pic[$i * $PieceOfLine + $j]->GetFileSize()) . "字节"
                   ?>
                </div>
              </td>
            </tr>
          </table>
        </td>
        <?
    }
    //最后补上空单元格
    for($i = 0; $i < $PieceOfLine - $Mod; $i++)
    {
    ?>
        <td width="184" height="180">&nbsp; </td>
    <?
    }

    echo "</tr>\n";
    ?>
    </table>
    </body>
    </html>
      

  6.   

    使用下面的代码,把名字改成list.php
    上传后,可是没有到达预期效果啊
    再帮助看看http://www.111.com/picture/list.php
    出现如下信息:
    &Auml;&iquest;&Acirc;&frac14; handle: Resource id #1 &micro;&micro;°&cedil;:  代码如下:<html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    </head><body>
    <table width="90%" border="0" cellspacing="0" cellpadding="0">
      <tr> 
    <?php 
    $handle=opendir('.'); 
    echo "&Auml;&iquest;&Acirc;&frac14; handle: $handle\n"; 
    echo "&micro;&micro;°&cedil;:\n"; 
    $rows=0; 
    while ($file = readdir($handle)) { 
       if(eregi("[_\.0-9a-z-]+[\.]+gif$",$file)) $rows++;//&Egrave;&iexcl;&micro;&Atilde;&Iacute;&frac14;&AElig;&not;&micro;&Auml;×&Uuml;&Ecirc;&yacute; 

    $n=0; 
    while ($file = readdir($handle)) { 
       if(eregi("[_\.0-9a-z-]+[\.]+gif$",$file))     echo "<td><table width='100%' border='0' cellspacing='0' cellpadding='0'> 
                  <tr>
                   <td><div align='center'><img src=$file\n width=100 height=100></div></td>//&Ecirc;&auml;&sup3;&ouml;&Iacute;&frac14;&AElig;&not;
                  </tr>
                  <tr>
                    <td>".$file."</td>//&Ecirc;&auml;&sup3;&ouml;&Icirc;&Auml;&frac14;&thorn;&Atilde;&ucirc;
                  </tr>
                 </table></td>";
         if($rows==0) echo "</tr>";
         $rows--;
         $n++;
         if($n==4)//$n==4,&Ouml;&cedil;&para;¨&Ograve;&raquo;&ETH;&ETH;&Iuml;&Ocirc;&Ecirc;&frac34;4&Otilde;&Aring;&Iacute;&frac14;&AElig;&not;&pound;&not;&Ograve;&sup2;&iquest;&Eacute;&Ograve;&Ocirc;&Eacute;è&Icirc;&ordf;&AElig;&auml;&Euml;&ucirc;&acute;ó&Oacute;&Uacute;0 &micro;&Auml;&Ecirc;&yacute;&Ouml;&micro;
           {
             echo "</tr>";
             $n=0;
           }
    }
    closedir($handle); 
    ?>
      </tr>
    </table>
    </body></html>
      

  7.   

    用这个代码吧,测试过的!
    <html>
    <head>
    <title>显示GIF图形</title>
    </head>
    <body>
    <table width="90%" border="0" cellspacing="0" cellpadding="0">
      <tr> 
    <?
    $handle=opendir("./images/");
    echo "目录 handle: $handle\n";
    echo "档案:\n";
    $rows=0;while ($file = readdir($handle)) {
    if(eregi("[_\.0-9a-z-]+[\.]+gif$",$file)) 
    $rows++;//取得图片的总数
    }$n=0;
    rewinddir($handle);
    while ($file = readdir($handle)) {
    if(eregi("[_\.0-9a-z-]+[\.]+gif$",$file))
        {
       echo "<td><table width=\"100%\" border=0 cellspacing=0 cellpadding=0>";
           echo "<tr>";
           echo "<td><div align=\"center\"><img src=\"/images/$file\n\" width=100 height=100></div></td>";
           echo "</tr>";
       echo "<tr>";
       echo "<td align=\"center\">$file</td>";
       echo "</tr>";
       echo "</table></td>";
           $rows--;
           $n++;
       }
       
       if($rows==0) 
       echo "</tr>";
       
       if($n==4)//$n==4,指定一行显示4张图片,也可以设为其他大于0 的数值
       {
       echo "</tr>";
           $n=0;
       }
    }
    closedir($handle);
    ?>
    </tr>
    </table>
    </body>
    </html>
      

  8.   

    $handle=opendir("./images/");
    上面程序中的这个语句是什么意思?
    我没有看明白
      

  9.   

    TO:令狐虫
    include "util/img_ctrl.php";
    include "util/utils.php";
    这两个是什么意思
    哪里有这个两个咚咚
    谢谢
      

  10.   

    野马的那段程序
    保存为PHP文件或者HTM文件都
    好像也不行
    保存为PHP文件,显示如下:
    目录 handle: 档案:  
    保存为HTM文件,显示如下:
    "; echo " 
    "; echo "  "; echo " 
    "; echo " "; echo " $file "; echo " 
    "; echo " "; $rows--; $n++; } if($rows==0) echo ""; if($n==4)//$n==4,指定一行显示4张图片,也可以设为其他大于0 的数值 { echo ""; $n=0; } } closedir($handle); ?>
      

  11.   

    <?php
    if($go)
    {
    $hand=@opendir($dir);
    if(!$hand)
    {echo"此目录不存在!";}
    else
    {
    echo"显示 $dir 目录下的所用*.gif文件<br>";
    ?>
    <table>
    <?
    while($file=readdir($hand))
    {
    $r=explode(".",$file);
    $count=count($r)-1;
    $filetype=$r[$count];
    if($filetype=="gif")
    {
    ?><tr><td align=center>
    <img src=<? echo"$dir/$file";?> border=0><br><?=$file?></td></tr>
    <?
    }
    }
    closedir($hand);
    }
    }
    ?>
    </table>
    <form name=form action=dir.php method=post>
    请输入目录:<input type=text name=dir value="."><input type=submit name=go value="显示此目录下的*.gif文件">
    </form>-----------------------------------------------
    地址:http://211.161.21.130:8080/EBB/ 是空闲时写的,而且近来比较忙,所以只实现基本的功能。 
    还请提出宝贵的意见。 测试好后将免费提供下载 
    关注我的网站:http://www.phome.net
      

  12.   

    演示:http://211.161.21.130:8081/work/dir.php