summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
Diffstat (limited to 'it.class')
-rw-r--r--it.class12
1 files changed, 12 insertions, 0 deletions
diff --git a/it.class b/it.class
index 55d57db..30dbf92 100644
--- a/it.class
+++ b/it.class
@@ -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);