1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[ticket/15311] Use cache directory if can't use system temp

PHPBB3-15311
This commit is contained in:
Rubén Calvo
2017-10-23 17:02:05 +02:00
parent e8a70dcb24
commit 01a8487244
46 changed files with 145 additions and 57 deletions

View File

@@ -42,14 +42,25 @@ class filesystem implements filesystem_interface
*/
protected $symfony_filesystem;
/**
* @var string
*/
protected $cache_temp_dir;
/**
* @var string
*/
protected $temp_dir;
/**
* Constructor
*/
public function __construct()
public function __construct($cache_temp_dir)
{
$this->chmod_info = array();
$this->symfony_filesystem = new \Symfony\Component\Filesystem\Filesystem();
$this->working_directory = null;
$this->cache_temp_dir = $cache_temp_dir;
}
/**
@@ -742,4 +753,33 @@ class filesystem implements filesystem_interface
{
return helper::resolve_path($path, $prefix, $absolute, $return_array);
}
/**
* Get a temporary directory to write files
*
* @return string returns the directory
*/
public function get_temp_dir()
{
if (!isset($this->temp_dir))
{
$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);
}
return $this->temp_dir;
}
}