Exemplo n.º 1
0
 /**
  * Write the contents of the file
  * @param String $content
  * @param String $path
  * @param String $fileName
  * @param Boolean $overwrite
  * @param Boolean $replace
  * @return Boolean
  */
 public static function writeContent($content, $path, $fileName, $overwrite = true, $replace = true)
 {
     self::$path = $path;
     self::$fileName = $fileName;
     if (!self::checkPathExists()) {
         $log = new Log();
         $log->setLog(__FILE__, 'The directory is not exists: ' . $path);
         throw new Exception('The directory is not exists: ' . $path);
     }
     if (!self::checkPathPermission()) {
         $log = new Log();
         $log->setLog(__FILE__, 'The directory is not writable: ' . $path);
         throw new Exception('The directory is not writable: ' . $path);
     }
     if (!$overwrite && !$replace && self::checkFileExists()) {
         return false;
     }
     $owner = fileowner($path);
     $group = filegroup($path);
     $permission = 0777;
     $type = "w";
     if ($overwrite && !$replace) {
         $type = "a";
         $content = '\\n' . $content;
     }
     if ($overwrite && $replace) {
         @unlink($path . $fileName);
     }
     $open = fopen($path . $fileName, $type);
     fwrite($open, $content);
     fclose($open);
     chmod($path . $fileName, $permission);
     #chown($path.$fileName,$owner);
     #chgrp($path.$fileName,$group);
     return true;
 }