예제 #1
0
 /**
  * Copy Dir
  * Copy a directory and all its contents
  *
  * @param string $fromDir Full path to dir to copy
  * @param string $toDir Full path to new location of copy
  * @return bool True on pass, false on fail
  */
 public static function copy_dir($fromDir, $toDir)
 {
     $file_tools = new RarsFileTools(get_class($this));
     $result = false;
     $readFromDir = $fromDir;
     $readToDir = $toDir;
     $file_tools->create_dir($readToDir);
     if (is_dir($readFromDir)) {
         $filesArray = array();
         $filesArray = $file_tools->read_dir_contents($readFromDir);
         // do recursive delete if dir contains files //
         foreach ($filesArray as $name) {
             if (is_dir($readFromDir . '/' . $name)) {
                 $result = self::copy_dir($fromDir . '/' . $name, $toDir . '/' . $name);
             } elseif (file_exists($readFromDir . '/' . $name)) {
                 $result = self::copy_file($fromDir . '/' . $name, $toDir . '/' . $name, false);
             }
         }
     }
     return $result;
 }
예제 #2
0
 /**
  * Log Error
  * Log the error to log file
  *
  * @param array $error Error data array
  * @param string $log_book The log book to write to
  * @return bool False on fail
  */
 public static function log_error($error, $log_book = 'rars-error-log')
 {
     if (empty($error)) {
         return false;
     }
     // get file contents
     $log = array();
     if (is_file(RARS_BASE_PATH . "storage/log/{$log_book}.php")) {
         $log = RarsFileTools::read_file_contents(RARS_BASE_PATH . "storage/log/{$log_book}.php", 'array');
     }
     // set date time
     $date_time = @date('d m Y - h:i:s', time());
     $entry = "<?php /* [{$date_time}] [{$error['error']}]";
     $entry .= isset($error['type']) ? " [type: {$error['type']}]" : "";
     $entry .= isset($error['file']) ? " [file: {$error['file']}]" : "";
     $entry .= isset($error['line']) ? " [line: {$error['line']}]" : "";
     $entry .= " [message: {$error['string']}] */ ?>\n\r";
     $log[] = $entry;
     if (count($log) > 100) {
         array_shift($log);
     }
     $log_string = implode('', $log);
     if (!is_dir(RARS_BASE_PATH . 'storage/log')) {
         mkdir(RARS_BASE_PATH . 'storage/log');
     }
     RarsFileTools::write_file_contents(RARS_BASE_PATH . "storage/log/{$log_book}.php", $log_string);
 }