Skip to content

Implemented Feature #60524 (sys_temp_dir) #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions main/php_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions main/php_open_temporary_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions php.ini-development
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,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.
Expand Down
4 changes: 4 additions & 0 deletions php.ini-production
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,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.
Expand Down
8 changes: 8 additions & 0 deletions tests/basic/req60524.phpt
Original file line number Diff line number Diff line change
@@ -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