-
-
Notifications
You must be signed in to change notification settings - Fork 994
Expand file tree
/
Copy pathtemp.php
More file actions
77 lines (65 loc) · 1.5 KB
/
temp.php
File metadata and controls
77 lines (65 loc) · 1.5 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\filesystem;
use phpbb\filesystem\exception\filesystem_exception;
class temp
{
/**
* @var filesystem
*/
protected $filesystem;
/**
* @var string
*/
protected $cache_temp_dir;
/**
* @var string Temporary directory path
*/
protected $temp_dir;
/**
* Constructor
*/
public function __construct(filesystem $filesystem, string $cache_temp_dir)
{
$this->filesystem = $filesystem;
$this->cache_temp_dir = $cache_temp_dir;
}
/**
* Get a temporary directory to write files
*
* @return string returns the directory
*/
public function get_dir()
{
if ($this->temp_dir === null)
{
$tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : '';
// Prevent trying to write to system temp dir in case of open_basedir
// restrictions being in effect
if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir))
{
$tmp_dir = $this->cache_temp_dir;
if (!is_dir($tmp_dir))
{
$this->filesystem->mkdir($tmp_dir, 0777);
}
}
$this->temp_dir = helper::realpath($tmp_dir);
if ($this->temp_dir === false)
{
throw new filesystem_exception('FILESYSTEM_CANNOT_CREATE_DIRECTORY', $tmp_dir);
}
}
return $this->temp_dir;
}
}