8 * Delete an entire directory structure
10 * @param string $path Path to delete
14 public static function recursiveDelete($path)
16 if (!is_dir($path) || is_link($path)) {
19 foreach (scandir($path) as $file) {
20 if ($file == '.' || $file == '..') {
23 $filepath = $path . DIRECTORY_SEPARATOR . $file;
24 if (!static::recursiveDelete($filepath)) {
32 * Create a full URL with protocol and host name
34 * @param string $path Path to the file, with leading /
36 * @return string Full URL
38 public static function fullUrl($path)
40 if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) {
45 return $prot . '://' . $_SERVER['HTTP_HOST'] . $path;
49 * Removes malicious parts from a file name
51 * @param string $file File name from the user
53 * @return string Fixed and probably secure filename
55 public static function sanitizeFilename($file)
58 $file = str_replace(array('\\', '//'), '/', $file);
59 $file = str_replace('/../', '/', $file);
60 if (substr($file, 0, 3) == '../') {
61 $file = substr($file, 3);
63 if (substr($file, 0, 1) == '../') {
64 $file = substr($file, 1);