路径问题,无法打开文件夹~
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> 新建目录</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> 目录</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 ; } |
路径怎么弄才是正确的?
3
收起
正在回答 回答被采纳积分+1
2回答
PHP常用技术与ThinkPHP5框架开发
- 参与学习 人
- 提交作业 225 份
- 解答问题 3372 个
掌握用PHP开发互联网网站的必备功能,掌握当下主流的Linux系统开发,并熟练使用热门框架ThinkPhp开发电商团购项目,是通向PHP工程师必经之路。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧