PHP read directory and delete (can delete files in the directory)_PHP tutorial

WBOY
Release: 2016-07-20 11:08:40
Original
885 people have browsed it

PHP reads directory deletion (can delete files in the directory). This article provides a PHP directory management program. It can manage and delete files, folders, and other files in the directory. It can support the management of unlimited directories. .

php tutorial to read directory deletion (can delete files in the directory)
This article provides a php directory management program, which can manage and delete files, folders, and other various files in the directory. Supports the management of unlimited directories.
*/

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('');
$max = 3;
$j = 0;
if(count($dirs) == 2){
echo'

';
print("");
print("");
print("");
echo '< ;/tr>
" );
print('');
print($dirs[ 0]);
print('
');
print("
< ;img src='type/dir.png'/>");
print('');
print($dirs[1]);
print('
');
print("
");
print("  ");
print("
';
}else{
echo'while($j <= (count($dirs) -1)){
print("
");
if(($j + 1) % $max = = 0){
echo '';
if(($j + 1) != count($dirs)){
echo '';
}
}
$j++;
}
echo '
");
print('');
print($ dirs[$j]);
print('
');
print("
';
}
$i = 0;
if(count ($files) == 2){
echo'';
print( "");
print("");
print("");
echo '
 ");
print($newdir -> change2line($files[0]));
print("
< ;img src='type/".$newdir -> getfiletype($files[1]).".png'/> ");
print($newdir -> change2line($files[ 1]));
print("
");
print("  " );
print("
';
}else{
echo'';
while($i <= (count($files) -1)){
print ("");
if(($i + 1) % 3 == 0){
echo '';
if(($i + 1) != count($files)){
echo '';
}
}

$i++;
}
echo '
 ");
print ($newdir -> change2line($files[$i]));
print("
';
}
?>


class .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 = ''.$basename.'';
  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; 
  }
 //
 }

?>


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444856.htmlTechArticlePHP 读取目录 删除(可删除目录下文件)本文章提供一款php目录管理程序,他可以对目录下的文件,文件夹,等各种文件进行管理删除操作,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template