Blame view

class_mcFile.inc.php 1.68 KB
sn committed
1
<?php
Frederick committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
class mcFile {

	/**
	 *
	 *
	 * @param string $param_filename
	 * @param string $param_text
	 * @param string $param_kindof -- r|r+|w|w+|a|a+ @see http://de3.php.net/manual/de/function.fopen.php
	 *					r - ptr at the beginning
	 *					w - ptr at the beginning and file size 0
	 *					a - ptr at the end
	 * @return bool
	 */
	public static function write($param_filename, $param_text, $param_kindof = null) {
		
		if($param_filename && $param_text) {
			
			if($param_kindof === null) {
				$param_kindof = 'a';
			}
			try {
				@$var_file = fopen($param_filename,$param_kindof);

				if ($var_file === false) {

					return false;
				} else {

					fputs($var_file, $param_text);
					fputs($var_file, mcCONST::LINEBREAK.mcCONST::LINEBREAK);
				}
				fclose($var_file);
				return true;
			} catch (Exception $e) {
				mcException::handleException($e);
			}
		} else {
			return false;
		}
	}

43
	public static function getFileContent($param_filename, $param_asString = false) {
44 45 46 47 48 49 50 51
		if(is_readable($param_filename)) {
			try {
				$handle = fopen ($param_filename, "r");
				$array_content = array();
				while (!feof($handle)) {
					$array_content[] = fgets($handle);
				}
				fclose ($handle);
52 53 54 55 56 57 58 59 60 61 62
				
				if($param_asString) {
					$filecontent_string = '';
					foreach($array_content as $line) {
						$filecontent_string .= $line;
					}					
					return $filecontent_string;
				} else {
					return $array_content;
				}

63 64 65 66 67 68 69 70
			} catch (Exception $e) {
				mcException::handleException($e);
				return false;
			}
		} else {
			return Error::newError('DevError', 'file could not read', $param_code);
		}
	}
71 72 73 74

	public static function deleteFile($param_filename) {
		return unlink($param_filename);
	}
Frederick committed
75 76 77
}

?>