示例#1
0
 /**
  * Copies a directory to another destination, recursively.
  *
  * @param string $from Full or relative path to directory.
  * @param string $to   Full or relative path to destination directory.
  *
  * @uses   File::getFullPath To format path to file.
  * @uses   self::create To create a directory.
  * @uses   self::copy To recursively copy subdirectories.
  * @uses   File::copy To copy files to the destination.
  *
  * @return boolean If the directory and its contents were copied successfully.
  */
 public static function copy($from, $to)
 {
     $from = File::getFullPath($from);
     /* Create destination directory. */
     $copied = self::create($to);
     /* Open a directory handle. */
     $handle = opendir($from);
     /* Read entries from the directory handle. */
     while (($entry = readdir($handle)) !== false) {
         /* Skip directory handles for current and previous directories. */
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         /* Check whether the current entry is a directory and is not a symbolic link */
         if (is_dir($from . DIRECTORY_SEPARATOR . $entry) && !is_link($from)) {
             $copied = self::copy($from . DIRECTORY_SEPARATOR . $entry, $to . DIRECTORY_SEPARATOR . $entry);
         } else {
             $copied = File::copy($from . DIRECTORY_SEPARATOR . $entry, $to . DIRECTORY_SEPARATOR . $entry);
         }
     }
     /* Close directory handle */
     closedir($handle);
     return $copied;
 }
示例#2
0
 /**
  * @covers Core\Helpers\File::copy
  */
 public function testCopyingFile()
 {
     $this->assertTrue(File::copy($this->baseName, $this->uploadedFile));
 }