|
|
@@ -139,34 +139,75 @@ class Zend_Cache_Backend
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * Return a system-wide tmp directory
|
|
|
+ * Determine system TMP directory and detect if we have read access
|
|
|
+ *
|
|
|
+ * inspired from Zend_File_Transfer_Adapter_Abstract
|
|
|
*
|
|
|
- * @return string System-wide tmp directory
|
|
|
+ * @return string
|
|
|
+ * @throws Zend_Cache_Exception if unable to determine directory
|
|
|
*/
|
|
|
- static function getTmpDir()
|
|
|
+ public function getTmpDir()
|
|
|
{
|
|
|
- if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
|
|
- // windows...
|
|
|
- foreach (array($_ENV, $_SERVER) as $tab) {
|
|
|
- foreach (array('TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
|
|
|
- if (isset($tab[$key])) {
|
|
|
- $result = $tab[$key];
|
|
|
- if (($key == 'windir') or ($key == 'SystemRoot')) {
|
|
|
- $result = $result . '\\temp';
|
|
|
- }
|
|
|
- return $result;
|
|
|
+ $tmpdir = array();
|
|
|
+ foreach (array($_ENV, $_SERVER) as $tab) {
|
|
|
+ foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
|
|
|
+ if (isset($tab[$key])) {
|
|
|
+ if (($key == 'windir') or ($key == 'SystemRoot')) {
|
|
|
+ $dir = realpath($tab[$key] . '\\temp');
|
|
|
+ } else {
|
|
|
+ $dir = realpath($tab[$key]);
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- return '\\temp';
|
|
|
- } else {
|
|
|
- // unix...
|
|
|
- if (isset($_ENV['TMPDIR'])) return $_ENV['TMPDIR'];
|
|
|
- if (isset($_SERVER['TMPDIR'])) return $_SERVER['TMPDIR'];
|
|
|
- return '/tmp';
|
|
|
+ if ($this->_isGoodTmpDir($dir)) {
|
|
|
+ return $dir;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $upload = ini_get('upload_tmp_dir');
|
|
|
+ if ($upload) {
|
|
|
+ $dir = realpath($upload);
|
|
|
+ if ($this->_isGoodTmpDir($dir)) {
|
|
|
+ return $dir;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (function_exists('sys_get_temp_dir')) {
|
|
|
+ $dir = sys_get_temp_dir();
|
|
|
+ if ($this->_isGoodTmpDir($dir)) {
|
|
|
+ return $dir;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // Attemp to detect by creating a temporary file
|
|
|
+ $tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
|
|
|
+ if ($tempFile) {
|
|
|
+ $dir = realpath(dirname($tempFile));
|
|
|
+ unlink($tempFile);
|
|
|
+ return $dir;
|
|
|
}
|
|
|
+ if ($this->_isGoodTmpDir('/tmp')) {
|
|
|
+ return '/tmp';
|
|
|
+ }
|
|
|
+ if ($this->_isGoodTmpDir('\\temp')) {
|
|
|
+ return '\\temp';
|
|
|
+ }
|
|
|
+ Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Verify if the given temporary directory is readable and writable
|
|
|
+ *
|
|
|
+ * @param $dir temporary directory
|
|
|
+ * @return boolean true if the directory is ok
|
|
|
+ */
|
|
|
+ protected function _isGoodTmpDir($dir)
|
|
|
+ {
|
|
|
+ if (is_readable($dir)) {
|
|
|
+ if (is_writable($dir)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/**
|