/** * */ protected static function getTempDir() { if (null === self::$TempDir) { $temp_dir = ini_get('upload_tmp_dir'); if ($temp_dir && (!is_dir($temp_dir) || !is_readable($temp_dir))) { $temp_dir = ''; } if (!$temp_dir && function_exists('sys_get_temp_dir')) { // PHP v5.2.1+ // sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts $temp_dir = sys_get_temp_dir(); } $temp_dir = realpath($temp_dir); $open_basedir = ini_get('open_basedir'); if ($open_basedir) { // e.g. "/var/www/vhosts/getid3.org/httpdocs/:/tmp/" $temp_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $temp_dir); $open_basedir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $open_basedir); if (substr($temp_dir, -1, 1) != DIRECTORY_SEPARATOR) { $temp_dir .= DIRECTORY_SEPARATOR; } $found_valid_tempdir = false; $open_basedirs = explode(':', $open_basedir); foreach ($open_basedirs as $basedir) { if (substr($basedir, -1, 1) != DIRECTORY_SEPARATOR) { $basedir .= DIRECTORY_SEPARATOR; } if (preg_match('#^' . preg_quote($basedir) . '#', $temp_dir)) { $found_valid_tempdir = true; break; } } if (!$found_valid_tempdir) { $temp_dir = ''; } unset($open_basedirs, $found_valid_tempdir, $basedir); } if (!$temp_dir) { $temp_dir = '*'; // invalid directory name should force tempnam() to use system default temp dir } self::$TempDir = $temp_dir; unset($open_basedir, $temp_dir); } return self::$TempDir; }