private static function getFileHandle($filename, $mode='c') {
		$write = in_array($mode,array('c','c+'));

		if($write) {
			//make sure the directory exists and is writable
			$directory = dirname($filename);
			if(!file_exists($directory)) {
				if(!mkdir($directory,0777,true)) {
					return false;
				}
			}
			elseif(!is_dir($directory)) {
				return false;
			}
			elseif(!is_writable($directory)) {
				return false;
			}
		}
		
		//get file pointer
		$fh = fopen($filename,$mode);

		if(!$fh) return false;

		//lock file with appropriate lock type
		if($write) {
			if(!flock($fh,LOCK_EX)) {
				self::closeFile($fh);
				return false;
			}	
		}
		else {
			if(!flock($fh,LOCK_SH)) {
				self::closeFile($fh);
				return false;
			}
		}
		
		return $fh;
	}
private static function getFileHandle($filename, $mode='c') {
		$write = in_array($mode,array('c','c+'));

		if($write) {
			//make sure the directory exists and is writable
			$directory = dirname($filename);
			if(!file_exists($directory)) {
				if(!mkdir($directory,0777,true)) {
					return false;
				}
			}
			elseif(!is_dir($directory)) {
				return false;
			}
			elseif(!is_writable($directory)) {
				return false;
			}
		}
		
		//get file pointer
		$fh = fopen($filename,$mode);

		if(!$fh) return false;

		//lock file with appropriate lock type
		if($write) {
			if(!flock($fh,LOCK_EX)) {
				self::closeFile($fh);
				return false;
			}	
		}
		else {
			if(!flock($fh,LOCK_SH)) {
				self::closeFile($fh);
				return false;
			}
		}
		
		return $fh;
	}
private static function getFileHandle ( $ filename , $ mode = 'c' ) { $ write = in_array ( $ mode , array ( 'c' , 'c+' ) ) ; if ( $ write ) { //make sure the directory exists and is writable $ directory = dirname ( $ filename ) ; if ( ! file_exists ( $ directory ) ) { if ( ! mkdir ( $ directory , 0777 , true ) ) { return false ; } } elseif ( ! is_dir ( $ directory ) ) { return false ; } elseif ( ! is_writable ( $ directory ) ) { return false ; } } //get file pointer $ fh = fopen ( $ filename , $ mode ) ; if ( ! $ fh ) return false ; //lock file with appropriate lock type if ( $ write ) { if ( ! flock ( $ fh , LOCK_EX ) ) { self :: closeFile ( $ fh ) ; return false ; } } else { if ( ! flock ( $ fh , LOCK_SH ) ) { self :: closeFile ( $ fh ) ; return false ; } } return $ fh ; }
Get a file handle from a file name. Will create the directory if it doesn't exist already. Also, automatically locks the file with the proper read or write lock.
@param String $filename The full file path.
@param String $mode The file mode.  Accepted modes are 'c', 'c+', and 'r'.
@return resource The file handle
Get a file handle from a file name . Will create the directory if it doesn t exist already . Also automatically locks the file with the proper read or write lock .