路径问题,无法打开文件夹~

路径问题,无法打开文件夹~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//index.php 代码
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
    <title>WEB在线文件管理器</title>
 
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
 
    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询(media queries)功能 -->
    <!-- 警告:通过 file:// 协议(就是直接将 html 页面拖拽到浏览器中)访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
 
    <?php 
      //读取管理项目、并且展示
      require_once 'lib/dir.func.php';
      date_default_timezone_set("PRC");
      error_reporting(E_ALL&~E_NOTICE);
      define('WEBROOT''../phpMyAdmin');
      $path=$_REQUEST['path']?$_REQUEST:WEBROOT;
      //var_dump($path);
       // exit;
      $info=read_directory($path);
      // print_r($info);
      if (!is_array($info)) {
        exit('读取失败');
      }
     ?>
 
    <div class="container">
  <div class="row clearfix">
    <div class="col-md-12 column">
      <nav class="navbar navbar-default" role="navigation">
        <div class="navbar-header">
           <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">切换导航</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button> <a class="navbar-brand" href="index.php"><span class="glyphicon glyphicon-home"></span>首页</a>
        </div>
         
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav">
            <li class="active">
              <a  href="#"><span class="glyphicon glyphicon-folder-open"></span>&nbsp;新建目录</a>
            </li>
            <li>
              <a  href="#"><span class="glyphicon glyphicon-file"></span>新建文件</a>
            </li>
            <li>
              <a  href="#"><span class="glyphicon glyphicon-upload"></span>上传文件</a>
            </li>
            <li>
              <a  href="#"><span class="glyphicon glyphicon-info-sign"></span>系统信息</a>
            </li>
      
              </ul>
            </li>
          </ul>
          <form class="navbar-form navbar-left" role="search">
            <div class="form-group">
              <input type="text" class="form-control" />
            </div> <button type="submit" class="btn btn-default">搜索</button>
          </form>
          <ul class="nav navbar-nav navbar-right">
              </ul>
            </li>
          </ul>
        </div>
         
      </nav>
      <div class="jumbotron nofollow">
        <h1>
          WEB在线文件管理器
        </h1>
        <p>
          WEB在线文件管理器主要是用于管理项目文件,实现修改、增加、删除等操作。
        </p>
        <p>
          <a rel="nofollow" class="btn btn-primary btn-large" href="#">查看更多 »</a>
        </p>
      </div>
      <table class="table table-bordered table-hover table-condensed">
        <thead>
          <tr>
            <th>
              类型
            </th>
            <th>
              名称
            </th>
            <th>
              读、写、执行
            </th>
            <th>
              访问时间
            </th>
            <th>
              操作
            </th>
          </tr>
        </thead>
        <tbody>
            <!-- 目录部分 -->
            <?php 
              if (is_array($info['dir'])) {
                foreach ($info['dir'as  $val) {
                 ?>
                    <tr class="success">
                      <td><span class="glyphicon glyphicon-folder-open"></span>&nbsp;目录</td>
                      <td><?php echo $val['showName']; ?></td>
                      <td>
                        <span class="glyphicon <?php echo $val[readable]?'glyphicon-ok':'glyphicon-remove'; ?>"></span>
                        <span class="glyphicon <?php echo $val[writable]?'glyphicon-ok':'glyphicon-remove'; ?>"></span>
                        <span class="glyphicon <?php echo $val[executable]?'glyphicon-ok':'glyphicon-remove'; ?>"></span>
                      </td>
                      <td><?php echo $val['atime']; ?></td>
                      <td>
                        <a href="index.php?path=<?php echo $val['fileName']; ?>" class="btn btn-primary btn-sm">打开</a>
                        <a href="#" class="btn btn-primary btn-sm">重命名</a>
                        <a href="#" class="btn btn-primary btn-sm">剪切</a>
                        <a href="#" class="btn btn-primary btn-sm">复制</a>
                        <a href="#" class="btn btn-danger btn-sm">删除</a>
                      </td>
                    </tr>
                 <?php
                }
              }
             ?>
             
            <!-- 文件部分 -->
            <?php 
              if (is_array($info['file'])) {
                foreach ($info['file'as  $val) {
                 ?>
                    <tr class="warning">
                      <td><span class="glyphicon glyphicon-file"></span>文件</td>
                      <td><?php echo $val['showName']; ?></td>
                      <td>
                        <span class="glyphicon <?php echo $val[readable]?'glyphicon-ok':'glyphicon-remove'; ?>"></span>
                        <span class="glyphicon <?php echo $val[writable]?'glyphicon-ok':'glyphicon-remove'; ?>"></span>
                        <span class="glyphicon <?php echo $val[executable]?'glyphicon-ok':'glyphicon-remove'; ?>"></span>
                      </td>
                      <td><?php echo $val['atime']; ?></td>
                      <td>
                        <a href="#" class="btn btn-primary btn-sm">查看</a>
                        <a href="#" class="btn btn-primary btn-sm">下载</a>
                        <a href="#" class="btn btn-primary btn-sm">编辑</a>
                        <a href="#" class="btn btn-primary btn-sm">剪切</a>
                        <a href="#" class="btn btn-primary btn-sm">复制</a>
                        <a href="#" class="btn btn-danger btn-sm">删除</a>
                      </td>
                    </tr>
                 <?php
                }
              }
             ?>
 
 
        </tbody>
      </table>
    </div>
  </div>
</div>
 
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
  </body>
</html>
 
 
//dir.func.php代码
<?php 
 
 
/**
 * 读取目录下的信息返回
 * @param  [type] $path [description]
 * @return [type]       [description]
 */
function read_directory($path){
    if (!is_dir($path)) {
        return false;
    }
    $info = [];
    $handle = opendir($path);
    while (($item = readdir($handle))!== false ) {
        if ($item != '.' && $item != '..') {
            $filePath $path.DIRECTORY_SEPARATOR.$item;
            $info['fileName'] = $filePath;
            $info['showName'] = $item;
                                //is_readable()检测文件是否可读
            $info['readable'] = is_readable($filePath)?true:false;
                                //is_writable()检测文件是否可写入
            $info['writable'] = is_writable($filePath)?true:false;
                                //is_writable()检测文件是否可写执行
            $info['executable'] = is_executable($filePath)?true:false;
                                //fileatime() 指定文件的上次访问时间
            $info['atime'] = date('Y/m/d H:i:s',fileatime($filePath));
 
            if (is_file($filePath)) {
                $arr['file'][] = $info;
            }
            if (is_dir($filePath)) {
                $arr['dir'][] = $info;
            }
        }
    }
    closedir($handle);
    return $arr;
}


http://img1.sycdn.imooc.com//climg/5c2097ec0001988a09570281.jpg

http://img1.sycdn.imooc.com//climg/5c2097ec0001961b08570526.jpg

http://img1.sycdn.imooc.com//climg/5c2097ec00016b6e09460810.jpg

路径怎么弄才是正确的?

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕查理 2018-12-24 17:06:20

您好,当前执行的index.php与phpMyAdmin文件是否在同一目录下,如果是则路径直接写文件名称或者./phpMyAdmin即可。../表示上级目录。祝学习愉快!

  • 提问者 初见若安 #1
    你没懂我的意思 。教程中,老师的目录架构和我的目录框架是一样的,老师直接写的就是目录名,我的电脑上必须要写../webAdmin才能把这个读取出来,index.php读取出来,但是再在index.php 下打开其它文件夹就不行了。
    2018-12-24 17:19:50
  • 好帮手慕查理 回复 提问者 初见若安 #2
    您好,代码中$path=$_REQUEST['path']?$_REQUEST:WEBROOT;错误应该是:$path=$_REQUEST['path']?$_REQUEST['path']:WEBROOT;。当存在路径时应该使用路径的值,而不是$_REQUEST。祝学习愉快!
    2018-12-24 18:39:51
提问者 初见若安 2018-12-24 16:27:47

http://img1.sycdn.imooc.com//climg/5c2098390001961b08570526.jpg

在这样的框架下,在设置常量的时候,我的系统必须要加上../path,这个index.php才能正常访问。但是如果加个了../,其它的都打不开

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码