diff options
author | Urban Müller | 2017-03-15 15:26:58 +0100 |
---|---|---|
committer | Urban Müller | 2017-03-15 15:26:58 +0100 |
commit | a833ef8465c738d117d2f72dab588f04bc0982ce (patch) | |
tree | 09eae89bc0a03a08bef3c339d0d623acf7242186 /it.class | |
parent | a29ada8124f7ea5bbad4387dd908eeaa57b1957c (diff) | |
download | itools-a833ef8465c738d117d2f72dab588f04bc0982ce.tar.gz itools-a833ef8465c738d117d2f72dab588f04bc0982ce.tar.bz2 itools-a833ef8465c738d117d2f72dab588f04bc0982ce.zip |
add add_dir(), add mkdir to file_put
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -985,6 +985,14 @@ static function mail($p) } /** + * Add an extra md5 based directory name on bottom of path. foo/bar -> foo/07/bar + */ +static function add_dir($path) +{ + return dirname($path) . "/" . substr(md5(basename($path)), 0, 2) . "/" . basename($path); +} + +/** * Reads a file and returns it as string or in one of several formats. Two params: filename and flags * @param $filename name of file to read or - for stdin * @param $p['keyval'] each line of the file is one tab-separated key/value pair, return assoc array @@ -1017,6 +1025,7 @@ static function file_get($filename, $p = array()) * @param $data data to write, string by default * @param $p['keyval'] $data must be an assoc array and is written as tab-separated lines * @param $p['lines'] write array of lines, appending newline + * @param $p['mkdir'] create parent directory (one level) */ static function file_put($filename, $data, $p = array()) { @@ -1025,6 +1034,9 @@ static function file_put($filename, $data, $p = array()) else if ($p['lines']) $data = count((array)$data) ? join("\n", (array)$data) ."\n" : ""; + if ($p['mkdir'] && $filename != "-") + @mkdir(dirname($filename)); + if (($result = file_put_contents($filename == "-" ? "php://stdout" : "$filename.tmp." . getmypid(), $data)) !== false && $filename != "-") $result = rename("$filename.tmp." . getmypid(), $filename); |