How to fix "Missing a temporary folder" in WordPress
PHP could not create the temporary file that every upload begins as, so WordPress was handed an error instead of a file. The folder is a PHP setting on the server. Defining WP_TEMP_DIR in wp-config.php does not clear the message, because that sets a different folder.
- By
- WP Ministry
- Published
- Tested on
- WordPress 7.1.3, PHP 8.3.35
In short
- Nothing is lost. The upload did not arrive, and everything already on the site is as it was.
- The folder is PHP's and is set on the server. WordPress has no setting for it.
- Defining WP_TEMP_DIR does not clear this message. It moves a different folder.
- A short PHP file shows which folder PHP uses and what is wrong with it.
- Where you cannot change PHP's settings, the repair is the host's to make. Send them what the check shows.
"Missing a temporary folder." means PHP could not create the temporary file that every upload begins as. PHP receives an uploaded file itself and stores it in a folder set on the server. When it cannot create a file there, WordPress is handed an error in place of the file and shows this message.
Nothing has been lost. The file you sent did not arrive, and everything already on the site is as it was. Installing from the plugin directory and running updates send no file from your computer, so they do not show this message.
Two temporary folders, and which one this is
You may have been told to add a WP_TEMP_DIR line to wp-config.php. That line sets a different folder.
- PHP's folder is where an upload lands. It is the one named by PHP's
upload_tmp_dirsetting or, when that is empty, the system's temporary folder, such as/tmp. PHP's manual listsupload_tmp_diramong the settings that can be made only inphp.inior the web server's configuration. Aphp_valueline in.htaccess, a.user.inifile andini_set()inwp-config.phpdo not change it. - WordPress's folder is where WordPress puts temporary files it makes itself, such as the download of an update. It uses
WP_TEMP_DIRif that is defined. Otherwise it takes the first of these it can write to: the system's temporary folder,upload_tmp_dir, thenwp-content.
This message comes only from the first. In WordPress's code it is the text for one PHP upload error, number 6, and nothing else. Defining WP_TEMP_DIR moves WordPress's folder and leaves uploads failing with the same message. When WordPress's own folder fails, the message is a different one, such as "Could not create temporary file."
Where it goes wrong
A page request passes through each of these in turn. This one comes from PHP, the language WordPress runs on.
- Browser
- DNS
- HTTPS
- CDN or firewall
- Web server
- PHP (this error comes from here)
- WordPress
- Database and files
What causes it
PHP's temporary folder is missing, or PHP may not write to it
CommonPHP's upload_tmp_dir setting, or the system's own temporary folder, points at a folder that is not there or that the user PHP runs as cannot write to. Nothing in WordPress sets this folder, so look for a change on the server, such as a move, a different PHP version or an edited PHP setting.
Fix: Find out which folder PHP uses and what is wrong with it, or Ask the host to repair PHP's temporary folder, or Set upload_tmp_dir where you control PHP's settings
open_basedir does not include the temporary folder
Sometimesopen_basedir limits PHP to a list of folders. PHP's manual says the system's temporary folder has to be in that list for an upload to succeed.
Fix: Find out which folder PHP uses and what is wrong with it, or Ask the host to repair PHP's temporary folder, or Add the temporary folder to open_basedir
The disk or the account's quota has no room for a new file
SometimesPHP cannot create the temporary file when the disk is full, or when the account has used up its allowance of space or of files.
Fix: Find out which folder PHP uses and what is wrong with it, or Ask the host to repair PHP's temporary folder, or Free space on the disk
How to fix it
Find out which folder PHP uses and what is wrong with it
- Easy
- Low risk
- About 10 minutes
- Steps tested on WordPress 7.1.3
Step 1: Create a file named temp-check.php
Put it in the site's main folder, beside
wp-config.php, with this content.temp-check.php<?php header( 'Content-Type: text/plain' ); function report( $label, $folder ) { echo $label, ': ', $folder, "\n"; error_clear_last(); $exists = @is_dir( $folder ); $error = error_get_last(); if ( $error && false !== strpos( $error['message'], 'open_basedir' ) ) { echo " Inside open_basedir: no\n"; return; } echo ' Exists: ', $exists ? 'yes' : 'no', "\n"; echo ' PHP can write to it: ', $exists && is_writable( $folder ) ? 'yes' : 'no', "\n"; $free = $exists ? @disk_free_space( $folder ) : false; echo ' Free space: ', false === $free ? 'unknown' : round( $free / 1048576 ) . ' MB', "\n"; } $set = ini_get( 'upload_tmp_dir' ); $limit = ini_get( 'open_basedir' ); $user = function_exists( 'posix_getpwuid' ) ? posix_getpwuid( posix_geteuid() )['name'] : 'unknown'; echo 'PHP runs as: ', $user, "\n"; echo 'open_basedir: ', $limit ? $limit : 'not set', "\n"; echo 'upload_tmp_dir: ', $set ? $set : 'not set', "\n"; if ( $set ) { report( 'Folder named by upload_tmp_dir', $set ); } report( 'System temporary folder', sys_get_temp_dir() );Step 2: Open it in your browser
Go to
https://example.com/temp-check.php, with your own domain. Run it this way and not from a command line, where PHP can have other settings.Step 3: Read the answers
When
upload_tmp_dirnames a folder, PHP tries it first and falls back to the system's folder if it cannot write there. The message appears when neither can be used.- "Inside open_basedir: no": PHP is not allowed to use that folder. Go to the fix for
open_basedir. - "Exists: no" or "PHP can write to it: no": the folder is missing, or closed to the user on the first line. Ask the host, or set
upload_tmp_diryourself. - "Free space" at or near 0 MB: free some space.
- Every answer is good: the cause is one PHP's code cannot see, such as a quota on the number of files. Take it to the host.
- "Inside open_basedir: no": PHP is not allowed to use that folder. Go to the fix for
Step 4: Delete the file
It tells anyone who opens it how your server is laid out.
To undo it: Delete temp-check.php.
Ask the host to repair PHP's temporary folder
- Easy
- No risk
- About 15 minutes
On hosting where you cannot edit php.ini, this is the fix. The folder and the setting belong to the server.
Step 1: Send the host the facts
textUploads to my site fail with "Missing a temporary folder." (PHP upload error 6, UPLOAD_ERR_NO_TMP_DIR). PHP runs as: (from the check) open_basedir: (from the check) upload_tmp_dir: (from the check) System temporary folder: (from the check, with the lines under it) Please make sure the folder PHP stores uploads in exists, can be written to by that user, is inside open_basedir, and has free space and free inodes. Or set upload_tmp_dir to a folder in my account.Step 2: Say what changed
If the message began after a move to another server, a change of PHP version or a change of plan, say so. It tells them where to look.
Step 3: Upload again when they reply
Run the check once more too. Its answers should all be good.
How to tell whether a fault is the host's or the site's covers what else to send a host and what to expect back.
Set upload_tmp_dir where you control PHP's settings
- Advanced
- Low risk
- About 15 minutes
Use this on a server you run yourself, or where your hosting panel lets you edit php.ini.
Step 1: Make a folder for uploads to land in
Put it inside your account and outside the folder the site is served from, for example
/home/example/tmp. The user on the first line of the check has to be able to write to it. The guide to file permissions explains which user that is, and why 755 is enough when that user owns the folder. Ifopen_basediris set, choose a folder inside its list, so that WordPress can read the file once PHP has stored it.Step 2: Name the folder in php.ini
In an Apache virtual host the same setting is
php_admin_value upload_tmp_dir /home/example/tmp. In a PHP-FPM pool it isphp_admin_value[upload_tmp_dir] = /home/example/tmp.php.iniupload_tmp_dir = /home/example/tmpStep 3: Restart PHP
PHP reads
php.iniwhen it starts. Where PHP runs as part of the web server, restart the web server. Where it runs as PHP-FPM, restart PHP-FPM.Step 4: Run the check again
The
upload_tmp_dir:line should name your folder, with "PHP can write to it: yes" under it. Then upload the file.
To undo it: Remove the line and restart PHP.
Add the temporary folder to open_basedir
- Takes care
- Back up first
- About 10 minutes
- Steps tested on WordPress 7.1.3
open_basedir lists the folders PHP may use. Who can change the list depends on where it was set.
- In your hosting panel's PHP settings: add the temporary folder to the list there.
- By the host, in the server's configuration: only the host can change it. PHP lets a site narrow a list the server set, never widen it. Send the host what the check shows, as in the second fix.
- In your site's own
.htaccessfile: follow these steps. They are for Apache with PHP running as part of the web server.
Step 1: Find the line
Open
.htaccessin the site's main folder and search foropen_basedir. If it is not there, the list is set in one of the other two places.Step 2: Add the folder to the end of the list
Use the folder the check calls "System temporary folder", after a colon. For a site in
/home/example/public_htmland a temporary folder of/tmp, the line becomes:.htaccessphp_value open_basedir "/home/example/public_html:/tmp"Step 3: Save, and run the check again
The
open_basedir:line should show the longer list, and the folder should read "PHP can write to it: yes".Step 4: Upload the file again
It should arrive as it did before the message began.
To undo it: Put your copy of .htaccess back.
Free space on the disk
- Takes care
- Low risk
- About 20 minutes
PHP shows this message when it cannot create the temporary file at all. A disk with no room for a new file stops it there, and so does an account that has used its allowance of space or of files. When PHP creates the file and runs out of room while filling it, the message is "Failed to write file to disk." instead.
Step 1: Check how full the account is
Your hosting panel shows how much of your disk allowance is used. If it also shows a count of files, which it may call inodes, check that too.
Step 2: Or check from the command line
Over SSH, the first command shows space and the second shows inodes, for the disk that holds the folder. Use the folder from the check in place of
/tmp.bashdf -h /tmp df -i /tmpStep 3: Remove what you no longer need
Look first at backup archives kept on the server, old log files and copies of the site left over from a move. Download anything you might want before you delete it.
Step 4: If the full disk is not yours
A temporary folder such as
/tmpcan be on a disk the whole server shares. Only the host can clear that one.
When to get help
If the check shows a folder that exists, can be written to and has room, and uploads still fail with this message, the cause is somewhere PHP's own code cannot see. Finding it takes access to the server's configuration and logs. The same is true when the host says the folder is fine and the message stays.
Common questions
Is "Failed to write file to disk." the same problem?
It is the next one along. PHP numbers its upload errors: 6 is "Missing a temporary folder" and 7 is "Failed to write file to disk." With 7, PHP created the temporary file and could not write the upload into it. Check free space first, then the folder, using the same file.
Why did it start when nothing on the site changed?
Because the setting is not on the site. Nothing in WordPress, a plugin or a theme chooses the folder an upload lands in. Ask what changed on the server: a move, a new PHP version, a setting edited in the hosting panel, or a disk that filled up.
Can I install a plugin or a theme while uploads are broken?
Yes. Unzip it on your computer and upload its folder over SFTP, into wp-content/plugins/ or wp-content/themes/. It then appears in the dashboard, ready to activate. Files sent this way do not pass through PHP's upload folder. If an upload fails with a message about the file's size instead, the fix is raising PHP's upload limits. For an update that stopped halfway, use the runbook for a failed update.
- GuideLocked out of WordPress admin: find which lockout you have and get back in
- GuideSlow WordPress admin: how to find the cause and fix it
- ResourceWooCommerce checkout is down: a runbook
- GuideWordPress site not showing up on Google: what to check, in order
- Guideadmin-ajax.php high CPU usage in WordPress: how to find what is calling it
- GuideHow to change WordPress permalinks without breaking your old links

