-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelperFunctions.php
41 lines (35 loc) · 1016 Bytes
/
helperFunctions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
function tempdir($dir = null, $prefix = 'tmp_', $mode = 0700, $maxAttempts = 1000)
{
if (is_null($dir))
{
$dir = sys_get_temp_dir();
}
$dir = rtrim($dir, DIRECTORY_SEPARATOR);
if (!is_dir($dir) || !is_writable($dir))
{
return false;
}
if (strpbrk($prefix, '\\/:*?"<>|') !== false)
{
return false;
}
$attempts = 0;
do
{
$path = sprintf('%s%s%s%s', $dir, DIRECTORY_SEPARATOR, $prefix, mt_rand(100000, mt_getrandmax()));
} while (
!mkdir($path, $mode) &&
$attempts++ < $maxAttempts
);
return $path;
}
function rmdir_recursive($dir) {
$it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
foreach($it as $file) {
if ($file->isDir()) rmdir($file->getPathname());
else unlink($file->getPathname());
}
rmdir($dir);
}