| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This code is taken from PEAR/File from Michael Wallner <mike@php.net>
|
|
|
5 |
* to avoid an extra dependency for a single function.
|
|
|
6 |
*
|
|
|
7 |
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
|
|
8 |
* that is available through the world-wide-web at the following URI:
|
|
|
9 |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
|
|
10 |
* the PHP License and are unable to obtain it through the web, please
|
|
|
11 |
* send a note to license@php.net so we can mail you a copy immediately.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
require_once('PEAR.php');
|
|
|
15 |
define('FILE_WIN32', defined('OS_WINDOWS') ? OS_WINDOWS : !strncasecmp(PHP_OS, 'win', 3));
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Returns the temp directory according to either the TMP, TMPDIR, or
|
|
|
19 |
* TEMP env variables. If these are not set it will also check for the
|
|
|
20 |
* existence of /tmp, %WINDIR%\temp
|
|
|
21 |
*
|
|
|
22 |
* @static
|
|
|
23 |
* @access public
|
|
|
24 |
* @return string The system tmp directory
|
|
|
25 |
*/
|
|
|
26 |
function tmpDir()
|
|
|
27 |
{
|
|
|
28 |
if (FILE_WIN32) {
|
|
|
29 |
if (isset($_ENV['TEMP'])) {
|
|
|
30 |
return $_ENV['TEMP'];
|
|
|
31 |
}
|
|
|
32 |
if (isset($_ENV['TMP'])) {
|
|
|
33 |
return $_ENV['TMP'];
|
|
|
34 |
}
|
|
|
35 |
if (isset($_ENV['windir'])) {
|
|
|
36 |
return $_ENV['windir'] . '\\temp';
|
|
|
37 |
}
|
|
|
38 |
if (isset($_ENV['SystemRoot'])) {
|
|
|
39 |
return $_ENV['SystemRoot'] . '\\temp';
|
|
|
40 |
}
|
|
|
41 |
if (isset($_SERVER['TEMP'])) {
|
|
|
42 |
return $_SERVER['TEMP'];
|
|
|
43 |
}
|
|
|
44 |
if (isset($_SERVER['TMP'])) {
|
|
|
45 |
return $_SERVER['TMP'];
|
|
|
46 |
}
|
|
|
47 |
if (isset($_SERVER['windir'])) {
|
|
|
48 |
return $_SERVER['windir'] . '\\temp';
|
|
|
49 |
}
|
|
|
50 |
if (isset($_SERVER['SystemRoot'])) {
|
|
|
51 |
return $_SERVER['SystemRoot'] . '\\temp';
|
|
|
52 |
}
|
|
|
53 |
return '\temp';
|
|
|
54 |
}
|
|
|
55 |
if (isset($_ENV['TMPDIR'])) {
|
|
|
56 |
return $_ENV['TMPDIR'];
|
|
|
57 |
}
|
|
|
58 |
if (isset($_SERVER['TMPDIR'])) {
|
|
|
59 |
return $_SERVER['TMPDIR'];
|
|
|
60 |
}
|
|
|
61 |
return '/tmp';
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
?>
|