PHP directory/File copy/Copy Custom function sharing

Source: Internet
Author: User
Tags file copy

Folder file copy/Copy functions are as follows

/**  *  folder file copy  *  *  @param  string  $src   source folder  *  @param   string  $dst   Destination folder  *  @return  bool  */function dir_copy ($src  =  ",   $DST  =  ') {    if  (Empty ($src)  | |
 empty ($DST))     {        return false;
   &NBSP}      $dir  = opendir ($SRC);
    dir_mkdir ($DST);     while  (false !==  ($file  = readdir ($dir))      {        if  ($file  !=  '. ')
 &&  ($file  !=  ' ... '))         {             if  (Is_dir ($src  . /'  .  $file)              {                 dir_copy ($src  .  '/'  .  $file,  $dst  .  '/'  
  $file);             }              else              {                copy ($
src .  '/'  .  $file,  $dst  .  '/'  .  $file);             }       
 &NBSP}     }     closedir ($dir);
    return true; /**  *  Create folder  *  *  @param  string  $path   folder path  *  @param  int   $mode  Access  *  @param  bool  $recursive   Whether to recursively create  *  @return  bool  */
Function dir_mkdir ($path  =  ',  $mode  = 0777,  $recursive  = true) {
    clearstatcache ();     if  (!is_dir ($path))     {      
  mkdir ($path,  $mode,  $recursive);
        return chmod ($path,  $mode);
    }     return true; }




PHP Copy folder and all the following files, refer to the following:

function XCopy ($source, $destination, $child) {
//Usage:
//XCopy ("Feiy", "Feiy2", 1): Copy feiy files to Feiy2, including subdirectories
//XCopy ("Feiy", "Feiy2", 0): Copy feiy files to Feiy2, excluding subdirectories
//Parameter description:
//$source: Source directory name
//$destination: Destination directory Name    
//$child: When replicating, is the contained subdirectory
if (!is_dir ($source)) {
echo ("Error:the $source are not a direction!");
return 0;
}
if (!is_dir ($destination)) {
mkdir ($destination, 0777);
$handle =dir ($source);
while ($entry = $handle->read ()) {
if ($entry!= ".") && ($entry!= "...")) {
if (Is_dir ($source.) /". $entry)) {
if ($child)
xCopy ($source.") /". $entry, $destination."      /". $entry, $child);
else{
Copy ($source. " /". $entry, $destination."      /". $entry);
}} return
1;
>


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.