1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
14
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
15
|
|
|
* @author mamba <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
trait FilesManagement |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Function responsible for checking if a directory exists, we can also write in and create an index.html file |
21
|
|
|
* |
22
|
|
|
* @param string $folder The full path of the directory to check |
23
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
public static function createFolder($folder) |
27
|
|
|
{ |
28
|
|
|
// try { |
29
|
|
|
// if (!mkdir($folder) && !is_dir($folder)) { |
|
|
|
|
30
|
|
|
// throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
|
|
|
31
|
|
|
// } else { |
|
|
|
|
32
|
|
|
// file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
|
|
|
33
|
|
|
// } |
34
|
|
|
// } |
35
|
|
|
// catch (Exception $e) { |
|
|
|
|
36
|
|
|
// echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
|
|
|
37
|
|
|
// } |
38
|
|
|
try { |
39
|
|
|
if (!file_exists($folder)) { |
40
|
|
|
if (!mkdir($folder) && !is_dir($folder)) { |
41
|
|
|
throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
catch (Exception $e) { |
48
|
|
|
echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param $file |
54
|
|
|
* @param $folder |
55
|
|
|
* @return bool |
56
|
|
|
*/ |
57
|
|
|
public static function copyFile($file, $folder) |
58
|
|
|
{ |
59
|
|
|
return copy($file, $folder); |
60
|
|
|
// try { |
61
|
|
|
// if (!is_dir($folder)) { |
|
|
|
|
62
|
|
|
// throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder)); |
|
|
|
|
63
|
|
|
// } else { |
|
|
|
|
64
|
|
|
// return copy($file, $folder); |
|
|
|
|
65
|
|
|
// } |
66
|
|
|
// } catch (Exception $e) { |
|
|
|
|
67
|
|
|
// echo 'Caught exception: ', $e->getMessage(), "\n", "<br>"; |
|
|
|
|
68
|
|
|
// } |
69
|
|
|
// return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param $src |
74
|
|
|
* @param $dst |
75
|
|
|
*/ |
76
|
|
|
public static function recurseCopy($src, $dst) |
77
|
|
|
{ |
78
|
|
|
$dir = opendir($src); |
79
|
|
|
// @mkdir($dst); |
80
|
|
|
while (false !== ($file = readdir($dir))) { |
81
|
|
|
if (($file !== '.') && ($file !== '..')) { |
82
|
|
|
if (is_dir($src . '/' . $file)) { |
83
|
|
|
self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
84
|
|
|
} else { |
85
|
|
|
copy($src . '/' . $file, $dst . '/' . $file); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
closedir($dir); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.