Location: PHPKode > projects > PAS SiteManager > passitemanager/class/FileCopy.class.php
<?php 
// Copyright 2002 Philippe Lewicki           hide@address.com
  /**
   * file copy Class
   *
   * It manage files Copy
   *
   * @author Philippe Lewicki  <hide@address.com>
   * @version 2.0.3
   * @package MyDB
   * @access public
   */

    class FileCopy extends BaseObject {
        var $originalFile ;
        var $destinationFile ;
        var $productionPermission = true ;
        var $overwriteDestination = false ;

        function FileCopy($originalFile ="", $destinationFile ="") {
            $this->orginialFile = $orgininalFile ;
            $this->destinationFile = $destinationFile ;
        }
        function copy($originalFile ="", $destinationFile = "") {
            $this->setDisplayErrors(false) ; 
            $doCopy = true ;
            if ($originalFile == "") {
                $originalFile = $this->originalFile ;
            }
            if ($destinationFile == "") {
                $destinationFile = $this->destinationFile ;
            }
            if ($destinationFile == "" || $originalFile == "") {
                $this->setError("Missing File Parameters : original file :".$originalFile." dest file :".$destinationFile) ;
                $doCopy = false ;
            }
            if (!file_exists($originalFile) || is_dir($originalFile)) {
                $this->setError("The original Doesn't exist or is a directory: ".$destinationFile) ;
                $doCopy = false ;
            }
            if (file_exists($destinationFile) && !$this->overwriteDestination) {
                $this->setError("The destination File exist and can't overwrite it: ".$destinationFile) ;
                $doCopy = false ;
            }
            if ($doCopy) {
                return copy($originalFile, $destinationFile) ;
            } else {
                return false ;
            }
        }
        function recursiveCopy ($dirName, $destDir) {
            if ($this->productionPermission) {
                $dirMode = 0750 ;
                $fileMode = 0640 ;
            } else {
                $dirMode = 0775 ;
                $fileMode = 0664 ;
            }
            $d = dir($dirName);
            if (!is_dir($destDir)) {
                mkdir($destDir, $dirMode) ;
                @chmod($destDir, $dirMode) ;
            }
            while($entry = $d->read()) {
                if ($entry != "." && $entry != "..") {
                    if (is_dir($dirName."/".$entry)) {
                        $this->recursiveCopy($dirName."/".$entry, $destDir."/".$entry);
                    } else {
                        //echo $dirName."/".$entry." -> ".$destDir."/".$entry."\n<br>";
                        $this->copy($dirName."/".$entry, $destDir."/".$entry) ;
                        @chmod ($destDir."/".$entry, $fileMode);
                    }
                }
            }
            $d->close();
            if ($this->isError()) {
                return false ;
            } else {
                return true ;
            }
        }
        function setProductionPermission($bool) {
            $this->productionPermission = $bool ;
        }
        function setOverwriteDestination($bool) {
            $this->overwriteDestination = $bool ;
        }
    }


?>
Return current item: PAS SiteManager