Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class File
- {
- public static function read($path, $default = NULL)
- {
- $fp = @fopen($path, 'r');
- if( ! $fp)
- return $default;
- flock($fp, LOCK_SH);
- $data = fread($fp, filesize($path));
- flock($fp, LOCK_UN);
- fclose($fp);
- return $data;
- }
- public static function write($path, $data)
- {
- self::check(dirname($path));
- $fp = fopen($path, 'c');
- flock($fp, LOCK_EX);
- ftruncate($fp, 0);
- fwrite($fp, $data);
- fflush($fp);
- flock($fp, LOCK_UN);
- fclose($fp);
- return $data;
- }
- public static function check($dir)
- {
- if( ! is_dir($dir))
- {
- // https://en.wikipedia.org/wiki/Chmod#System_call
- @mkdir($dir, 06740, true);
- @chmod($dir, 06740);
- }
- return $dir;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement