]> granicus.if.org Git - php/commitdiff
Implemented Feature #60524 (sys_temp_dir)
authorALeX Kazik <git@kazik.de>
Fri, 18 Jan 2013 16:13:39 +0000 (17:13 +0100)
committerStanislav Malyshev <stas@php.net>
Tue, 29 Jan 2013 06:37:43 +0000 (22:37 -0800)
Added a new configuration directive which allows it to change the
temporary directory, the default behavior is unchanged.

This is a useful option if you use all/some hosts inside of one .ini file
with sections and want to change the temp dir per user (maybe it's not
allowed to write outside the users home directory). Since the TMPDIR
variable affects the whole php that way can not be used for this scenario.

(see https://bugs.php.net/bug.php?id=60524)

main/main.c
main/php_globals.h
main/php_open_temporary_file.c
php.ini-development
php.ini-production
tests/basic/req60524.phpt [new file with mode: 0644]

index f87a1427feda4b034236f8c78044c30edb9f5f74..325ef7ed531b3ba23abb257b55ac6dde41355125 100644 (file)
@@ -521,6 +521,7 @@ PHP_INI_BEGIN()
        STD_PHP_INI_ENTRY("default_mimetype",           SAPI_DEFAULT_MIMETYPE,  PHP_INI_ALL,    OnUpdateString,                 default_mimetype,               sapi_globals_struct,sapi_globals)
        STD_PHP_INI_ENTRY("error_log",                          NULL,           PHP_INI_ALL,            OnUpdateErrorLog,                       error_log,                              php_core_globals,       core_globals)
        STD_PHP_INI_ENTRY("extension_dir",                      PHP_EXTENSION_DIR,              PHP_INI_SYSTEM,         OnUpdateStringUnempty,  extension_dir,                  php_core_globals,       core_globals)
+       STD_PHP_INI_ENTRY("sys_temp_dir",                       NULL,           PHP_INI_SYSTEM,         OnUpdateStringUnempty,  sys_temp_dir,                   php_core_globals,       core_globals)
        STD_PHP_INI_ENTRY("include_path",                       PHP_INCLUDE_PATH,               PHP_INI_ALL,            OnUpdateStringUnempty,  include_path,                   php_core_globals,       core_globals)
        PHP_INI_ENTRY("max_execution_time",                     "30",           PHP_INI_ALL,                    OnUpdateTimeout)
        STD_PHP_INI_ENTRY("open_basedir",                       NULL,           PHP_INI_ALL,            OnUpdateBaseDir,                        open_basedir,                   php_core_globals,       core_globals)
index 170431d079c63abf86e10f34422173b9a798a8e8..256765d665a53aa877b45b05fc70b61ab8c9fbd2 100644 (file)
@@ -85,6 +85,7 @@ struct _php_core_globals {
        char *open_basedir;
        char *extension_dir;
        char *php_binary;
+       char *sys_temp_dir;
 
        char *upload_tmp_dir;
        long upload_max_filesize;
index b43d6a78351c740e5bbe1e6a60a9fca334897a32..5d5e5b98d77a0db241cd404d1fd1c1cc05d2ca53 100644 (file)
@@ -196,6 +196,21 @@ PHPAPI const char* php_get_temporary_directory(void)
                return temporary_directory;
        }
 
+       /* Is there a temporary directory "sys_temp_dir" in .ini defined? */
+       {
+               char *sys_temp_dir = PG(sys_temp_dir);
+               if (sys_temp_dir) {
+                       int len = strlen(sys_temp_dir);
+                       if (len >= 2 && sys_temp_dir[len - 1] == DEFAULT_SLASH) {
+                               temporary_directory = zend_strndup(sys_temp_dir, len - 1);
+                               return temporary_directory;
+                       } else if (len >= 1 && sys_temp_dir[len - 1] != DEFAULT_SLASH) {
+                               temporary_directory = zend_strndup(sys_temp_dir, len);
+                               return temporary_directory;
+                       }
+               }
+       }
+
 #ifdef PHP_WIN32
        /* We can't count on the environment variables TEMP or TMP,
         * and so must make the Win32 API call to get the default
index a97cd0f9dad94e3bb1bacf5b23d26e55d72e0cf2..93a4b7d8a589ac34b190d188622bd6762b4e0537 100644 (file)
@@ -729,6 +729,10 @@ user_dir =
 ; On windows:
 ; extension_dir = "ext"
 
+; Directory where the temporary files should be placed.
+; Defaults to the system default (see sys_get_temp_dir)
+; sys_temp_dir = "/tmp"
+
 ; Whether or not to enable the dl() function.  The dl() function does NOT work
 ; properly in multithreaded servers, such as IIS or Zeus, and is automatically
 ; disabled on them.
index dce8fc970ccffe106e5cf54a9785f85e8a89f259..7d84c9b87979055c55f70dc8272ffcd988e5e8b0 100644 (file)
@@ -729,6 +729,10 @@ user_dir =
 ; On windows:
 ; extension_dir = "ext"
 
+; Directory where the temporary files should be placed.
+; Defaults to the system default (see sys_get_temp_dir)
+; sys_temp_dir = "/tmp"
+
 ; Whether or not to enable the dl() function.  The dl() function does NOT work
 ; properly in multithreaded servers, such as IIS or Zeus, and is automatically
 ; disabled on them.
diff --git a/tests/basic/req60524.phpt b/tests/basic/req60524.phpt
new file mode 100644 (file)
index 0000000..6803e1f
--- /dev/null
@@ -0,0 +1,8 @@
+--TEST--
+Req #60524 (Specify temporary directory)
+--INI--
+sys_temp_dir=/path/to/temp/dir
+--FILE--
+<?php echo sys_get_temp_dir(); ?>
+--EXPECT--
+/path/to/temp/dir