Created
February 24, 2012 15:57
-
-
Save rlemon/1901754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Datastore class | |
* for working with flat file data. | |
* */ | |
class Datastore { | |
public function __construct() { | |
} | |
public function read_file( $file ) { | |
$file = './' . $file; | |
if ( !file_exists( $file ) ) { | |
return false; | |
} | |
return file_get_contents( $file ); | |
} | |
public function save_file($relativepath, $contents, $append = false ) { | |
$parts = explode('/', $relativepath); | |
$file = array_pop($parts); | |
$dir = '.'; | |
foreach($parts as $part) { | |
if(!is_dir($dir .= '/' . $part)) { | |
$oldumask = umask(0); | |
mkdir($dir, 0777); | |
umask($oldumask); | |
} | |
} | |
file_put_contents($dir . '/' . $file, $contents, ($append?FILE_APPEND:0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment