Php folder and file mobile class-PHP source code

Source: Internet
Author: User
Ec (2); this is a file directory moving class. You only need to write your file directory name to be transferred in listDir. This folder and file moving class can be used, this method is suitable for collecting and downloading multiple files, such as instructions on the packaged files. & Lt ;? Example; & script ec (2); script

This is a file directory Movement class. You only need to write your file directory name to be transferred in listDir. This folder and file Movement class are suitable for collecting and downloading multiple files, for example, add instructions to the package file.

Die ();
Class s {
// Var $ path = 'flash ';
Var $ htm = '/index.htm ';
Var $ html = '/index.html ';
Var $ ladir = '/111cn.net ';

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 ,'
';
$ 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
";
}
}
}

// 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'); // 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.