+
+/**
+ * Transform a string in a path by seperating each letters by a '/'.
+ * @return path finishing with a '/'
+ */
+function
+s2p ($s)
+{
+ $p = '';
+ for ($i = 0; $i < strlen ($s); $i++)
+ $p .= $s{$i} . '/';
+ return $p;
+}
+
+function
+jirafeau_human_size ($octets)
+{
+ $u = array ('B', 'KB', 'MB', 'GB', 'TB');
+ $o = max ($octets, 0);
+ $p = min (floor (($o ? log ($o) : 0) / log (1024)), count ($u) - 1);
+ $o /= pow (1024, $p);
+ return round ($o, 1) . $u[$p];
+}
+
+function
+jirafeau_clean_rm_link ($link)
+{
+ $p = s2p ("$link");
+ if (file_exists (VAR_LINKS . $p . $link))
+ unlink (VAR_LINKS . $p . $link);
+ $parse = VAR_LINKS . $p;
+ $scan = array();
+ while (file_exists ($parse)
+ && ($scan = scandir ($parse))
+ && count ($scan) == 2 // '.' and '..' folders => empty.
+ && basename ($parse) != basename (VAR_LINKS))
+ {
+ rmdir ($parse);
+ $parse = substr ($parse, 0, strlen($parse) - strlen(basename ($parse)) - 1);
+ }
+}
+
+function
+jirafeau_clean_rm_file ($md5)
+{
+ $p = s2p ("$md5");
+ if (file_exists (VAR_FILES . $p . $md5))
+ unlink (VAR_FILES . $p . $md5);
+ if (file_exists (VAR_FILES . $p . $md5 . '_count'))
+ unlink (VAR_FILES . $p . $md5 . '_count');
+ $parse = VAR_FILES . $p;
+ $scan = array();
+ while (file_exists ($parse)
+ && ($scan = scandir ($parse))
+ && count ($scan) == 2 // '.' and '..' folders => empty.
+ && basename ($parse) != basename (VAR_FILES))
+ {
+ rmdir ($parse);
+ $parse = substr ($parse, 0, strlen($parse) - strlen(basename ($parse)) - 1);
+ }
+}
+