PHP lists all files and folders under the folder you are using

Source: Internet
Author: User

?
/************************************
Name:listdir
Author:riyao Chen
version:0.0.1
Date:2006-05-16
License:gpl


This class are to list all file & directory follow a directory
Parameter: $strdir, which directory you want list; $del _url,the Manage URL,


*********************************/
Class listdir{

var $dir;
var $edit _url= "";
var $del _url= "";

var $num = 0;

function Listdir ($strdir, $del _url= "", $edit _url= "")
{
$this->dir = $strdir;
$this->del_url = $del _url;
$this->edit_url = $edit _url;
}

function MakeDir ($StrDir)
{
Global $num;
if (Is_dir ($StrDir)) {
if ($dh = @opendir ($StrDir)) {
while (($file = Readdir ($DH))!== false) {

$newdir = $StrDir. $file;
if ($file = = "." | | $file = = "...")
{
Continue
}

$this->num = $this->num + 1;
Print Str_repeat ("", $this->num);

if (filetype ($newdir) = = "Dir")
{
print "<br>";
print "$file [directory]<br>\n];
}
Else
{

Print "<a href= '". $this->del_url. "? File= ". $newdir." ' >EDIT</a> <a href= ' ". $newdir." ' > $file </a> <br>\n ";
}
if (Is_dir ($newdir))
{
$this->makedir ($newdir.) /");
}

$this->num = $this->num-1;
}
print "<br>";
Closedir ($DH);
}
}

}

function Showdir ()
{
$this->makedir ($this->dir);
}
}

/*
Exemple

Include_once ("./class.dir.php");
$dir = new Listdir ("c:/", "http://127.0.0.1/index.php");
$dir->showdir ();

*/



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.