File manager basic display page
The verification code function mentioned in the previous chapter cannot see the function code for changing one as follows:
Title
Rendering display:
Click to display:
The above are the questions left in the last section of the previous chapter. Next, read this section content, this section is to make a similar windows file manager
Design ideas:
First find Current directory, determine whether the current directory is a file or a directory. You can view information about all files and directories in the current directory through the following code
The specific code is as follows:
array(),'file'=>array()); //循环遍历文件列表 while(false!==($filename=readdir($handle))){ //排除当前目录和父级目录 if($filename!='.' && $filename!='..'){ //处理文件路径和文件名 $filepath="$path/$filename"; //根据路径获取文件类型 $filetype=filetype($filepath); //如果既不是文件也不是目录,则跳过 if(!in_array($filetype,array('file','dir'))){ continue; } //将文件信息保存到数组中 $list[$filetype][]=array( //保存文件名和路劲 'filename'=>$filename, 'filepath'=>$filepath, //保存各种属性 'filesize'=>round(filesize($filepath)/1024), 'filemtime'=>date('Y/m/d H:i:s',filemtime($filepath)), ); } } //关闭文件句柄 closedir($handle); return $list; $path="."; $file_list=getFileList($path); echo ""; print_r($file_list); echo "";
The directory structure is as follows:
The print result is as follows:
Then set up the html page according to the windows directory folder, and traverse the file_list printed above.
filemanager_html.php code As follows:
文件管理器
名称 | 修改日期 | 大小 | 操作 |
---|---|---|---|
- | 打开 | ||
KB | 重命名复制删除 |
##Running result display:
So, how to perform specific operations of opening, renaming, copying and deleting files and directories? (This will be explained in the next section)