PHP 读取目录,删除
发布:smiling 来源: PHP粉丝网 添加日期:2014-09-09 11:31:11 浏览: 评论:0
本文章提供一款php目录管理程序,他可以对目录下的文件,文件夹,等各种文件进行管理删除操作,可以支持无限级目录的管理,代码如下:
- <?php
- include("class.php");
- $path = $_get['path'];
- if($path == ""){
- $path = "dir";
- }else{
- if(!strstr($path,"dir")){
- $path = "dir/".$path;
- }else{
- $path = $path;
- }
- }
- $newdir = new dirver();
- $newdir -> setpath($path);
- $newdir -> dirdata();
- $files = $newdir -> getfiles();
- $dirs = $newdir -> getdirs();
- //print_r($files);
- //print_r($dirs);
- echo('<link href="style.css" rel="stylesheet" type="text/css" />');
- $max = 3;
- $j = 0;
- if(count($dirs) == 2){
- echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
- print("<td width='33%'><img src='type/dir.png'/>");
- print('<a href="test.php?path='.$path."/".$dirs[0].'">');
- print($dirs[0]);
- print('</a>');
- print("</td>");
- print("<td width='33%'><img src='type/dir.png'/>");
- print('<a href="test.php?path='.$path."/".$dirs[1].'">');
- print($dirs[1]);
- print('</a>');
- print("</td>");
- print("<td width='33%'>");
- print(" ");
- print("</td>");
- echo '</tr></table>';
- }else{
- echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
- while($j <= (count($dirs) -1)){
- print("<td ><img src='type/dir.png'/>");
- print('<a href="test.php?path='.$path."/".$dirs[$j].'">');
- print($dirs[$j]);
- print('</a>');
- print("</td>");
- if(($j + 1) % $max == 0){
- echo '</tr>';
- if(($j + 1) != count($dirs)){
- echo '<tr>';
- }
- }
- $j++;
- }
- echo '</tr></table>';
- }
- $i = 0;
- if(count($files) == 2){
- echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
- print("<td width='33%'><img src='type/".$newdir -> getfiletype($files[0]).".png'/> ");
- print($newdir -> change2line($files[0]));
- print("</td>");
- print("<td width='33%'><img src='type/".$newdir -> getfiletype($files[1]).".png'/> ");
- print($newdir -> change2line($files[1]));
- print("</td>");
- print("<td width='33%'>");
- print(" ");
- print("</td>");
- echo '</tr></table>';
- }else{
- echo'<table width="800" border="0" cellpadding="5" cellspacing="5"><tr>';
- while($i <= (count($files) -1)){
- print("<td width=100><img src='type/".$newdir -> getfiletype($files[$i]).".png'/> ");
- print($newdir -> change2line($files[$i]));
- print("</td>");//开源代码phpfensi.com
- if(($i + 1) % 3 == 0){
- echo '</tr>';
- if(($i + 1) != count($files)){
- echo '<tr>';
- }
- }
- $i++;
- }
- echo '</tr></table>';
- }
- ?>
class.php,代码如下:
- <?php
- class for php4.x
- class dirver{
- /class var/
- var $path;
- var $flies;
- var $dirs;
- /
- function dirver(){
- $this -> path = "";
- $this -> files = array();
- $this -> dirs = array();
- }
- function dirdata(){
- if(isset($this -> path)){
- $handle = dir($this -> path);
- while(false !== ($data = $handle -> read())){
- if(is_dir($this -> connectname($this -> path,$data)) && $data != "." && $data != ".."){
- $this -> dirs[] = $data;
- continue;
- }
- if($data != "." && $data != ".." && is_file($this -> connectname($this -> path,$data))){
- $this -> files[] = $data;
- continue;
- }
- }
- $handle -> close();
- }else{
- return false;
- }
- }
- function setpath($src){
- if($src != ""){
- $this -> path = $src;
- }else{
- return false;
- }
- }
- /
- function connectname($path,$name){
- return $path."/".$name;
- }
- /
- function change2line($name){
- $basename = explode(".",$name);
- $basename = $basename[0];
- $tmp = $this -> path."/".$name;
- $tmp = '<a href="'.$tmp.'" target="_blank">'.$basename.'</a>';
- return $tmp;
- }
- function getfiletype($file){
- if($file != ""){
- $tmp = explode(".",$file);
- $type = $tmp[count($tmp)-1];
- return $type;
- }
- }
- function getfiles(){
- return $this -> files;
- }
- function getdirs(){
- return $this -> dirs;
- }
- //
- }
- ?>
Tags: PHP读取目录 PHP删除目录
- 上一篇:支持多级目录建立的php函数
- 下一篇:php批量重命名文件名
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)