开始新的列时READDIR移动到新的目录 [英] start new column when readdir moves to new dir

查看:112
本文介绍了开始新的列时READDIR移动到新的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原始问题:


确定,所以我使用READDIR抽丝从多个目录文件名。所以每次它启动它使一个新列即一个新的目录,我想知道是否有安排数据的方法。

  --- | USER1 |用户2 |用户3 |
--- | file1a | file2a | file3a |
--- | file1b | file2b | file3b |
--- | file1c | file2c | file3c |
--- | file1d | ^ | file3d |
--- | file1e | | | ^ |
--- | ^ |结束| | |
--- | | | DIR2 |结束|
--- |结束| #START | DIR3 |
--- | DIR1 | COL3 |等等|
--- | #START | | |
--- | COL2 | | |

如果这是可能的,这将是巨大的。至于在顶部显示用户名我有一部分已经下降。我只需要知道,如果列的部分可以做,如果是如何做到这一点。


这是我到目前为止的编码是:

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/ XHTML1-transitional.dtd>
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
< HEAD>
< META HTTP-EQUIV =Content-Type的CONTENT =text / html的;字符集= UTF-8/>
<标题>无标题文档< /标题>
< /头><身体GT;
<表边框=1>
< PHP
如果($处理=执行opendir(用户/')){
    而(假的!==($入门= READDIR($处理))){
        如果($项=&放!&放大器;!$ =进入..){
            呼应'<第i';
            回声$进入\\ N的;
            呼应'< /第i';
            }
                  }
        }
?>< PHP $文件夹= @scandir(用户);
    的foreach($文件夹为$项目){
         如果((SUBSTR($项目,0,1)=='')||(preg_match(/ \\ PHP $ /,$项目)))
                继续;        如果(is_dir(用户/ $项目)){
            $ target_folders = @scandir(用户/ $项/上传/);
            的foreach($ target_folders为$ target_item){
                如果((preg_match(/^[.]/\",$ target_item))||(is_dir(!用户/ $项/上传/ $ target_item))!);
                如果((SUBSTR($ target_item,0,1)==''))
                        继续;
                呼应'< TR>';
                呼应'< TD>';
                回声$ target_item;
                呼应'< / TD>';
                呼应'< / TR>';
                                    }
                            }
                 }
?>
< /表>
< /身体GT;
< / HTML>


解决方案

用下面的code ++实现:


 <!DOCTYPE HTML PUBLIC -  // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/ XHTML1-transitional.dtd>
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
< HEAD>
< META HTTP-EQUIV =Content-Type的CONTENT =text / html的;字符集= UTF-8/>
<标题>无标题文档< /标题>
< /头><身体GT;< PHP
呼应'<表类=表>< TR>';
$文件夹= @scandir(用户);
    的foreach($文件夹为$项):
     如果((SUBSTR($项目,0,1)=='')||(preg_match(/ \\ PHP $ /,$项目)))
                继续;
    ?>
    < TD ALIGN =顶>
          <表格的宽度=220BORDER =1VALIGN =顶>
               < TR>百分位宽度=210VALIGN =顶>< PHP的echo $项目;>< /第i< / TR>
              < PHP
               如果(is_dir(用户/ $项目))
            $ target_folders = @scandir(用户/ $项/上传/);
                的foreach($ target_folders为$ target_item){                如果((!preg_match(/^[.]/\",$ target_item))||(!is_dir(用户/ $项/上传/ $ target_item))){
                如果((SUBSTR($ target_item,0,1)==''))
                   继续;                   ?>< TR>< TD>< PHP的echo $ target_item;>< / TD>< / TR>< PHP                }
                }                   ?>
          < /表>
< / TD>
    < PHP
endforeach;呼应'< / TR>< /表>';
?>
<风格类型=文/ CSS>    TD {
垂直对齐:首位;
}< /风格>
< /身体GT;
< / HTML>

Original Issue:


ok so i am using readdir to snag file names from multiple directories. i was wondering if there is a way to arrange the data so that each time it starts a new directory it makes a new column i.e.

---| user1  | user2  | user3  |
---| file1a | file2a | file3a |
---| file1b | file2b | file3b |
---| file1c | file2c | file3c |
---| file1d |   ^    | file3d |
---| file1e |   |    |   ^    |
---|    ^   |  end   |   |    |
---|    |   |  dir2  |  end   |
---|   end  | #start |  dir3  |
---|   dir1 |  col3  |  etc.  |
---| #start |        |        |
---|  col2  |        |        |

if this is possible that would be great. as far as displaying the user names across the top i have that part down already. i just need to know if the columns part can be done and if so how to do it.


The coding that i have so far is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<table border="1">
<?php
if ($handle = opendir('Users/')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {


            echo '<th>';
            echo "$entry\n";
            echo '</th>';
            }
                  }
        }           
?>

<?php

 $folders = @scandir('Users');  
    foreach($folders as $item){
         if ((substr($item, 0, 1) == '.') || (preg_match("/\.php$/", $item)))
                continue;

        if (is_dir("Users/$item")){
            $target_folders = @scandir("Users/$item/uploaded/");
            foreach($target_folders as $target_item){
                if ((!preg_match("/^[.]/",$target_item)) || (!is_dir("Users/$item/uploaded/$target_item")));
                if ((substr($target_item, 0, 1) == '.'))
                        continue;
                echo '<tr>';
                echo '<td>';        
                echo $target_item;
                echo '</td>';
                echo '</tr>';
                                    }
                            }
                 }
?>
</table>
</body>
</html>

解决方案

Achieved with the following code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
echo '<table class="table"><tr>';
$folders = @scandir('Users');  
    foreach($folders as $item):
     if ((substr($item, 0, 1) == '.') || (preg_match("/\.php$/", $item)))
                continue;
    ?>
    <td align="top">
          <table width="220" border="1" valign="top">
               <tr><th width="210" valign="top"><?php echo $item;?></th></tr>
              <?php
               if (is_dir("Users/$item"))
            $target_folders = @scandir("Users/$item/uploaded/");
                foreach($target_folders as $target_item){

                if ((!preg_match("/^[.]/",$target_item)) || (!is_dir("Users/$item/uploaded/$target_item"))){
                if ((substr($target_item, 0, 1) == '.'))
                   continue;     

                   ?><tr><td><?php echo $target_item ;?></td></tr><?php

                }
                }

                   ?>
          </table>
</td>
    <?php
endforeach;

echo '</tr></table>';
?>


<style type="text/css">

    td {
vertical-align: top;
}



</style>
</body>
</html>

这篇关于开始新的列时READDIR移动到新的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆