About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
When a Media Library upload ends with "Missing a temporary folder.", PHP could not create the temporary file that every upload is written to first, and it reported that to WordPress before any WordPress code looked at the file. The repair is on the server: a temporary directory that exists, that the account running PHP can write to, and that PHP is allowed to use. A file that is simply too big gives a different message, covered in "The uploaded file exceeds the upload_max_filesize directive in php.ini": every limit on the upload path.
What the error means
The PHP manual lists the constant UPLOAD_ERR_NO_TMP_DIR with the text "Missing a temporary folder." and the value 6. WordPress 6.7.1 only repeats it. In wp_handle_upload() in wp-admin/includes/file.php it holds a list of PHP's upload error texts, and when $file['error'] is greater than 0 it returns the text at that position. Position 6 is __( 'Missing a temporary folder.' ). Our own reading: because PHP set the code before WordPress ran, the uploads folder, the media settings and the WP_TEMP_DIR constant are not what raised it.
PHP's page for upload_tmp_dir says the directory "Must be writable by whatever user PHP is running as". If it is not set, PHP uses "the system's default". The page continues: "If the directory specified here is not writable, PHP falls back to the system default temporary directory", and with open_basedir on, "the system default directory must be allowed for an upload to succeed".
In the PHP 8.3.14 source, main/rfc1867.c tries to create the upload's temporary file with the upload_tmp_dir value. When that fails it logs the warning File upload error - unable to create a temporary file and sets PHP_UPLOAD_ERROR_E. Our own reading: that is the code the manual lists as UPLOAD_ERR_NO_TMP_DIR, value 6. Our own reading of main/php_open_temporary_file.c: the fallback directory is checked against open_basedir, and a directory named in upload_tmp_dir is not. So the message means that the named directory (if any) and the fallback both failed.
The PHP manual gives upload_tmp_dir the mode INI_SYSTEM, defined as "Entry can be set in php.ini or httpd.conf". A line in .htaccess or .user.ini therefore cannot set it. For PHP-FPM, the manual shows that a pool file passes PHP settings with lines such as php_admin_value[memory_limit] = 32M.
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
upload_tmp_dir names a directory that does not exist, or that the PHP account cannot write to, and the fallback also fails |
Every upload fails with the message, whatever its size | The PHP error log holds unable to create a temporary file; the directory's owner and permissions do not suit the PHP account |
open_basedir is on and the system default temporary directory is outside it |
The same, often after upload_tmp_dir was removed or mistyped |
The open_basedir value in the effective configuration does not include the system default directory |
upload_tmp_dir is unset and the system default directory is missing or not writable for the PHP account |
The same | The loaded files hold no upload_tmp_dir line, and the default directory from step 4 under "Prove the cause before changing anything" is missing or not writable for the PHP account |
| Not this fault: the temporary file was created but could not be written | "Failed to write file to disk." (code 7) | WordPress lists that text separately from "Missing a temporary folder." |
Prove the cause before changing anything
All of these steps only read.
1. Match the wording. The text must be exactly "Missing a temporary folder." The size limit gives "The uploaded file exceeds the upload_max_filesize directive in php.ini.", and a write failure gives "Failed to write file to disk."
2. Look for the PHP warning. The PHP-FPM manual's example sets php_admin_value[error_log] = /var/log/fpm-php.www.log. Use the log file your own pool names. The POSIX page for grep says: "The grep utility shall search the input files, selecting lines matching one or more patterns".
grep "unable to create a temporary file" /var/log/fpm-php.www.log
A good result for this diagnosis is one or more lines with the time of a failed upload. No lines means the message comes from somewhere else, or PHP logs to another file.
3. Find the configuration PHP loads. The manual says running PHP with the --ini option lists the files that were loaded.
php --ini
Our own reading: this shows the command-line PHP, which can load different files from PHP-FPM, so also read the pool files in the PHP-FPM configuration directory.
4. Find PHP's default temporary directory. The manual describes sys_get_temp_dir() as returning "the path of the directory PHP stores temporary files in by default". From the command line, the PHP manual's options page lists -r <code> as "Run PHP <code> without using script tags <?..?>":
php -r 'echo sys_get_temp_dir();'
Our own reading: this gives the command-line PHP's answer. A pool or service that sets its own temporary directory can give a different one, so treat it as the place to look first.
5. Read the two settings. In the files from step 3, look for lines that start with upload_tmp_dir or open_basedir, and for pool lines such as php_admin_value[upload_tmp_dir]. Write down every value you find, with the file it came from.
6. Read the directories. For each directory named, including the default from step 4, check that it exists, and that its owner and permissions let the PHP-FPM account write to it. The pool file's user line names that account, described in the manual as the "Unix user of FPM processes".
Fix
Give PHP a temporary directory it can use
The directory has to exist, its owner or permissions have to let the PHP-FPM account write to it, and its path has to be the one you set below. On shared hosting the provider does this; on your own server it is a task for the server administrator. Once it exists, point PHP at it in the file where Prove step 5 found upload_tmp_dir, or in php.ini if no file held it. The two routes below are alternatives; use the one that matches.
Route 1: the value is in php.ini
First save the current state. POSIX cp with -p duplicates "The time of last data modification and time of last access" of the source file in the copy.
cp -p /etc/php/8.3/fpm/php.ini /etc/php/8.3/fpm/php.ini.2026-12-04
Risk: the next edit changes where PHP writes every upload for every site that uses this php.ini. A wrong path makes uploads fail on all of them. The manual says php.ini "is read when PHP starts up", and our own reading is that the edit has no effect until PHP-FPM is reloaded.
In that php.ini, set the line below to the directory you prepared.
upload_tmp_dir = /srv/uploads-tmp
Only if you need to back out: copy the saved file back over php.ini. This discards the edit and any other change made to the file since the copy, and uploads fail again until the cause is fixed.
Risk: the next command overwrites php.ini with the copy saved before the edit.
cp -p /etc/php/8.3/fpm/php.ini.2026-12-04 /etc/php/8.3/fpm/php.ini
Then reload PHP-FPM again, following the reload step below with its warning. After that, upload a small image to see the state you went back to.
Route 2: the value is in a PHP-FPM pool file
First save the current state:
cp -p /etc/php/8.3/fpm/pool.d/www.conf /etc/php/8.3/fpm/pool.d/www.conf.2026-12-04
Risk: the next edit changes where PHP writes the uploads of every site served by this pool, and a wrong path makes them all fail. Our own reading: it has no effect until the pool is reloaded.
In that pool file, set the line below. Our own reading: the manual shows php_admin_value[...] as the form for pool settings, so it should apply to this directive too.
php_admin_value[upload_tmp_dir] = /srv/uploads-tmp
Only if you need to back out: copy the saved file back over the pool file. This discards the edit and any other change made to the file since the copy.
Risk: the next command overwrites the pool file with the copy saved before the edit.
cp -p /etc/php/8.3/fpm/pool.d/www.conf.2026-12-04 /etc/php/8.3/fpm/pool.d/www.conf
Then reload PHP-FPM again, following the reload step below with its warning. After that, upload a small image to see the state you went back to.
Then reload PHP-FPM
Disruptive step: reloading PHP-FPM makes its pools read the edited file. Our own reading: requests being handled while it reloads can be interrupted, so choose a quiet time.
Reload the PHP-FPM service with your server's service manager, using the unit name for your PHP version.
To undo it: after you copy the saved file back, reload the service again.
Disruptive step: reloading PHP-FPM again makes its pools read the restored file, and requests being handled while it reloads can be interrupted.
Reload the PHP-FPM service as before. It brings back the settings from the copy you saved.
Then upload a small image to check.
The fallback is blocked by open_basedir
PHP's page says the system default directory "must be allowed" when open_basedir is on. There are two ways out. One is the route above, because our own reading of the source is that a writable upload_tmp_dir is not checked against open_basedir. The other is widening the open_basedir list to include the system default directory. Our own advice: the first route is narrower, because widening open_basedir lets every script of that site reach another directory, and that is a security decision for the server administrator, so no steps are given here for it.
Do not look in WordPress for this one
Our own reading of get_temp_dir() in WordPress 6.7.1: the WP_TEMP_DIR constant sets where WordPress puts its own temporary files, such as downloads. The error here comes from PHP's upload handling, so setting that constant does not clear it.
Example (illustrative): on web01, www.example.com runs under a PHP-FPM pool as the account example. After a migration, the pool file carries php_admin_value[upload_tmp_dir] = /srv/uploads-tmp, which was never created on web01, and open_basedir is /var/www/example.com/, which does not include /tmp. Every Media Library upload shows "Missing a temporary folder." and the pool log has File upload error - unable to create a temporary file. The administrator creates /srv/uploads-tmp for the account example, reloads PHP-FPM, and a small test image uploads.
Confirm the fix
- Check that the directory you named in
upload_tmp_direxists, and that its owner or permissions let the PHP-FPM account write to it. This only reads; on shared hosting, ask your provider. - Upload a small image in the Media Library. It should finish without the message.
- Look at the end of the PHP log for a new
unable to create a temporary fileline after the time of your change. There should be none. - Upload a file larger than a few megabytes, below your upload limit, so a bigger temporary file is also created.
What to watch afterwards
- After any PHP upgrade, pool change or move to a new server, upload one small file before telling anyone the site is ready.
- A count of
unable to create a temporary filelines per day in the PHP log is a simple signal to add to routine checks. - If you add
open_basedirto a pool later, repeat the upload test, because that is the second place this fault comes from.
Read next
Related articles you may want next.
- Troubleshooting"The uploaded file exceeds the upload_max_filesize directive in php.ini": every limit on the upload pathPHP 'The uploaded file exceeds the upload_max_filesize directive in php.ini': set upload_max_filesize, post_max_size and memory_limit together, reload FPM.Read article
- HostingWordPress "Sorry, you are not allowed to upload this file type.": the allowed list, the content check and the user's rightsWordPress 'Sorry, you are not allowed to upload this file type.' means the extension or content check failed. Find which one, then fix it safely.Read article
- Troubleshootingnginx 413 Request Entity Too Large: client_max_body_size and the limits behind itnginx 413 Request Entity Too Large on uploads: the default client_max_body_size is 1m. Read the error log, raise it per location and match PHP limits.Read article
Risks and limits
- These commands have not been run or lab-tested.
- The paths in the commands are examples. Use the files and directories your own PHP-FPM version and pool use.
upload_tmp_dircannot be set from.htaccessor.user.ini. On hosting where you cannot editphp.inior pool files, only the provider can change it.- Our own reading: a new value is read when PHP-FPM reloads. A path the PHP account cannot write to gives the same message as before.
- The wording of the PHP warning is from the PHP 8.3.14 source; other PHP versions may word it differently.
Sources
- Predefined Constants — PHP manual, no date shown, accessed 4 December 2026
- sys_get_temp_dir — PHP manual, no date shown, accessed 4 December 2026
- Description of core php.ini directives — PHP manual, no date shown, accessed 4 December 2026
- Where a configuration setting may be set — PHP manual, no date shown, accessed 4 December 2026
- The configuration file — PHP manual, no date shown, accessed 4 December 2026
- Configuration — PHP manual (FastCGI Process Manager), no date shown, accessed 4 December 2026
- wordpress-develop/src/wp-admin/includes/file.php at 6.7.1 — WordPress source at a fixed tag, no date shown, accessed 4 December 2026
- wordpress-develop/src/wp-includes/functions.php at 6.7.1 — WordPress source at a fixed tag, no date shown, accessed 4 December 2026
- php-src/main/rfc1867.c at php-8.3.14 — PHP source at a fixed tag, no date shown, accessed 4 December 2026
- grep — The Open Group Base Specifications Issue 7, 2018 edition, no date shown, accessed 4 December 2026
- cp — The Open Group Base Specifications Issue 7, 2018 edition, no date shown, accessed 4 December 2026
- Command line options — PHP manual, no date shown, accessed 4 December 2026
- php-src/main/php_open_temporary_file.c at php-8.3.14 — PHP source at a fixed tag, no date shown, accessed 4 December 2026
This article was originally published on .