wp_temp_dir does not change the /tmp temporary default directory

I have a problem changing the temporary folder. I have have define the new temporary folder using

define( 'WP_TEMP_DIR', dirname(__FILE__) . '/wp-content/temp/' );

before the line

/* That's all, stop editing! Happy publishing. */

but without any success. I have created a small test.php script to checking the success of changing to the new temporary folder such that

?php echo sys_get_temp_dir() . PHP_EOL; ?

with the output

/tmp

I have checked the permissions of the wp-config.php, wp-content/temp/ and wp-includes/functions.php files and they are the equivalent to 777.

I am not sure how to proceed and I have not found a lot information on internet. I hope someone could give me a hint. Thanks in advance

Topic filesystem uploads media Wordpress

Category Web


sys_get_temp_dir is not a WordPress function, it's a core PHP function. It cannot be modified or changed using WordPress constants. To modify this would require changes to the servers operating system by the root user.

Instead, WP_TEMP_DIR can be used to influence the value of get_temp_dir which is a WordPress function.

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.

https://developer.wordpress.org/reference/functions/get_temp_dir/

WP_TEMP_DIR gives you the opportunity to set up a temporary folder WordPress can use if it cannot find a system folder to do it. Perhaps because you are on a server that has been misconfigured, or perhaps systemd has been configured with PrivateTmp=true preventing /tmp from being used.

get_temp_dir is used when generating files for download, or for setting constants for 3rd party libraries.

I'm not sure what the problem is that you hoped to solve by changing the returned value of sys_get_temp_dir, but WP_TEMP_DIR is not the solution you hoped it to be, and does not do what you thought it did. You should create a question asking how to solve your original problem.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.