PHP folder and file Move class

Source: Internet
Author: User
Tags mkdir php tutorial

This is a file directory move class, as long as in Listdir write your file to transfer the directory name moved on it, this folder and file move class, more suitable for the collection of multiple files to download the operation, such as in the packaging file add instructions, etc. oh.

<?php Tutorial
Die ();
Class s{
var $path = ' flash ';
var $htm = '/index.htm ';
var $html = '/index.html ';
var $ladir = '/111cn.net tutorial ';

Public Function Full_copy ($source, $target)
{

if (Is_dir ($source) && $source!= $source. $this->ladir)
{
@mkdir ($target);
$d = Dir ($source);
while (FALSE!== ($entry = $d->read ()))
{
if ($entry = = '. ' | | $entry = = ' ... ')
{
Continue
}
$Entry = $source. '/' . $entry;
if (Is_dir ($Entry))
{
$this->full_copy ($Entry, $target. '/' . $entry);
Continue
}
Copy ($Entry, $target. '/' . $entry);
}
$d->close ();
}
Else
{
Copy ($source, $target);
}
}

//

Public Function Listdir ($dir _path)
{
if (Is_dir ($dir _path)) {
if ($dir _file=opendir ($dir _path)) {
while (($dir _list=readdir ($dir _file))!==false)
{
if ($dir _list!= "." && $dir _list!= "...")
{
$this->listsundir ($dir _path.) /". $dir _list);
$this->mkdir_r ($dir _path.) /". $dir _list. $this->ladir);
}
}
}else{
Echo ($dir _path);
}
}else{

Echo ($dir _path);
}
}

//

Public Function Listsundir ($dir _path)
{
if (Is_dir ($dir _path)) {
if ($dir _file=opendir ($dir _path)) {
while (($dir _list=readdir ($dir _file))!==false)
{
if ($dir _list!= "." && $dir _list!= "...")
{

$this->mkdir_r ($dir _path.) /". $dir _list. $this->ladir);


if ('/'. $dir _list = = $this->ladir)
{
Continue
}
Else
{
Echo $dir _path. " /". $dir _list, ' <br/> ';
$this->full_copy ($dir _path.) /". $dir _list, $dir _path." /". $this->ladir);
$this->deldir ($dir _path.) /". $dir _list);
}

$this->full_copy ($dir _path.) /". $dir _list, $dir _path." /". $dir _list. $this->ladir);
}
}
}else{
Echo ($dir _path);
}
}else{

Echo ($dir _path);
}
}

//

Public Function checkfile ($dir)
{
if (Is_dir ($dir))
{
if (Is_file ($dir. $htm) | | is_file ($dir. $html))
{
Continue
}
Else
{
$this->full_copy ($dir, $target);
}
}
}

Mkdir

function Mkdir_r ($dirName, $rights =0777)
{
$dirs = explode ('/', $dirName);
$dir = ';
foreach ($dirs as $part) {
$dir. = $part. ' /';
if (!is_dir ($dir) && strlen ($dir) >0 &&!is_file ($dirName))
{
mkdir ($dir, $rights);
echo "$dirName <br/>";
}
}
}

Delall

function Deldir ($dir)
{
if (Is_dir ($dir))
{
$rdir = $dir;
if ($dirlist = Scandir ($rdir))
{
Array_shift ($dirlist);
Array_shift ($dirlist);
foreach ($dirlist as $d) {
$rd = $rdir. ' /'. $d;
if (Isset ($d) && is_file ($rd)) {
Unlink ($RD);
}else{
$this->deldir ($RD);
}
}
RmDir ($rdir);
}else{
return false;
}
}
return true;
}
}

$s = new S ();
$s->listdir (' flash ');//To move the directory
?>

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.