get_temp_dir()
Determine a writable directory for temporary files.
Function's preference is the return value of sys_get_temp_dir(), followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR, before finally defaulting to /tmp/
In the event that this function does not find a writable location, It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file.
1 time — 0.00001 sec (speed of light) | 50000 times — 0.03 sec (speed of light) | PHP 7.1.11, WP 4.9.5
No Hooks.
Return
String
. Writable temporary directory.
Usage
get_temp_dir();
Examples
#1 Get the path of the temporary folder
echo get_temp_dir(); // /server/tmp/
#2 Create directory my_test in the temporary directory, if it does not already exist
$my_tmp_dir = get_temp_dir() . '/my_test'; if( ! is_dir($my_tmp_dir) ){ mkdir( $my_tmp_dir ); }
Changelog
Since 2.5.0 | Introduced. |