diff --git a/ext/standard/tests/file/bug52624.phpt b/ext/standard/tests/file/bug52624.phpt index c5e7a9cb0ec1c..ee61eb90e6f45 100644 --- a/ext/standard/tests/file/bug52624.phpt +++ b/ext/standard/tests/file/bug52624.phpt @@ -9,6 +9,4 @@ echo tempnam("directory_that_not_exists", "prefix_"); ?> --EXPECTF-- -Notice: tempnam(): file created in the system's temporary directory in %sbug52624.php on line %d - Warning: tempnam(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s on line %d diff --git a/ext/standard/tests/file/tempnam_variation3-win32.phpt b/ext/standard/tests/file/tempnam_variation3-win32.phpt index 5bc4f5ec884d1..68a77e57aa8ca 100644 --- a/ext/standard/tests/file/tempnam_variation3-win32.phpt +++ b/ext/standard/tests/file/tempnam_variation3-win32.phpt @@ -97,8 +97,6 @@ OK -- Iteration 3 -- OK -- Iteration 4 -- - -Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation3-win32.php on line %d Failed, not created in the correct directory %s vs %s 0 -- Iteration 5 -- diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c index 608f3ecf73bae..332ce7c08329f 100644 --- a/main/php_open_temporary_file.c +++ b/main/php_open_temporary_file.c @@ -303,7 +303,16 @@ PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_strin if (temp_dir && *temp_dir != '\0' && (!(flags & PHP_TMP_FILE_OPEN_BASEDIR_CHECK_ON_FALLBACK) || !php_check_open_basedir(temp_dir))) { - return php_do_open_temporary_file(temp_dir, pfx, opened_path_p); + fd = php_do_open_temporary_file(temp_dir, pfx, opened_path_p); + if (!(flags & PHP_TMP_FILE_SILENT) && dir && *dir != '\0') { + /* Default temporary directory fallback. */ + if (UNEXPECTED(fd == -1)) { + /* TODO: decide whether we should notice that even the fallback failed? */ + } else { + php_error_docref(NULL, E_NOTICE, "file created in the system's temporary directory"); + } + } + return fd; } else { return -1; } @@ -317,9 +326,6 @@ PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_strin fd = php_do_open_temporary_file(dir, pfx, opened_path_p); if (fd == -1) { /* Use default temporary directory. */ - if (!(flags & PHP_TMP_FILE_SILENT)) { - php_error_docref(NULL, E_NOTICE, "file created in the system's temporary directory"); - } goto def_tmp; } return fd;