Php method for recursive operation of files

Source: Internet
Author: User
This article mainly introduces PHP for file recursive operation method, interested in the friend's reference, I hope to be helpful to everyone.

Specific as follows:

<?php/* * Folder replication class */class Copyfile{public $fromFile;p ublic $toFile; */* $fromFile to copy who * $toFile copy to that */function Copyfil E ($fromFile, $toFile) {  $this->createfolder ($toFile);  $folder 1=opendir ($fromFile);  while ($f 1=readdir ($folder 1)) {    if ($f 1!= "." && $f 1!= ") {      $path 2= "{$fromFile}/{$f 1}";      if (Is_file ($path 2)) {          $file = $path 2;        $newfile = "{$toFile}/{$f 1}";        Copy ($file, $newfile);      } ElseIf (Is_dir ($path 2)) {        $toFiles = $toFile. ' /'. $f 1;        $this->copyfile ($path 2, $toFiles);}}}  /* * Recursively Create folder */function CreateFolder ($dir, $mode = 0777) {  if (Is_dir ($dir) | | @mkdir ($DIR, $mode)) {    return true;  }   if (! $this->createfolder (dirname ($dir), $mode)) {   return false;}  Return @mkdir ($dir, $mode);}} Use the method//introduce this class, direct new CopyFile (' to copy who ', ' Copy to that '),//$file = new CopyFile (' aaaa/aaaaa ', ' bbbbb/bbbb ');? >

Summary : The above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

Php method for paging function based on SQLite

How PHP implements the Observer pattern

thinkphp implementation of bulk Delete column method

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.