8 * Delete an entire directory structure
10 * @param string $path Path to delete
14 public static function recursiveDelete($path)
16 if (!file_exists($path)) {
19 if (!is_dir($path) || is_link($path)) {
22 foreach (scandir($path) as $file) {
23 if ($file == '.' || $file == '..') {
26 $filepath = $path . DIRECTORY_SEPARATOR . $file;
27 if (!static::recursiveDelete($filepath)) {
35 * Create a full URL with protocol and host name
37 * @param string $path Path to the file, with leading /
39 * @return string Full URL
41 public static function fullUrl($path = '')
43 if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) {
48 return $prot . '://' . $_SERVER['HTTP_HOST'] . $GLOBALS['phorkie']['cfg']['baseurl'] . $path;
52 * Removes malicious parts from a file name
54 * @param string $file File name from the user
56 * @return string Fixed and probably secure filename
58 public static function sanitizeFilename($file)
61 $file = str_replace(array('\\', '//'), '/', $file);
62 $file = str_replace('/../', '/', $file);
63 if (substr($file, 0, 3) == '../') {
64 $file = substr($file, 3);
66 if (substr($file, 0, 1) == '../') {
67 $file = substr($file, 1);