PHP 讀取目錄 刪除(可刪除目錄下檔案)

來源:互聯網
上載者:User
 代碼如下 複製代碼

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("&nbsp;&nbsp;");
 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'/>&nbsp;");
 print($newdir -> change2line($files[0]));
 print("</td>");
 print("<td width='33%'><img src='type/".$newdir -> getfiletype($files[1]).".png'/>&nbsp;");
 print($newdir -> change2line($files[1]));
 print("</td>");
 print("<td width='33%'>");
 print("&nbsp;&nbsp;");
 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'/>&nbsp;");
 print($newdir -> change2line($files[$i])); 
 print("</td>");
 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; 
  }
 //
 }

?>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.