Here is a more comprehensive take on how to fix "Missing a temporary folder"
.
Add echo ini_get("upload_tmp_dir");
somewhere to your code. It will print the path to that temporary folder that is supposedly missing. Check that the folder exists and is writable.
- If it doesn’t exist, then create it.
- If it exists but is not writable, try to make it writable.
- If you can’t create it / make it writable, try to change it to a folder that you can create & make writable using one of the approaches above (via
define("WP_TEMP_DIR", "...")
, php.ini
or doing directly ini_set("upload_tmp_dir", "...")
).
- If all of above fails (and it’s not unlikely that you won’t be allowed to change PHP configuration in many environments), you need to reach out to your hosting provider.
A bit more context:
The way file upload works in PHP apps is that when the user uploads a file, it is stored to a temporary directory by “the server” and the server then simply passes the path of this temporary file to the PHP app (= WordPress in this case). The app can then take the file and move it to the target location (e.g. wp-uploads).
If the temporary directory for some reason doesn’t exist, the server indicates that to the PHP app as UPLOAD_ERR_NO_TMP_DIR
which in this case WordPress converts into the infamous “Missing a temporary folder”.
What’s important is that this mechanism is completely independent on WordPress!. The temporary directory is configured via upload_tmp_dir
PHP ini config variable, i.e., it’s part of your server / PHP configuration. If it’s broken, it’s likely that you won’t be able to fix it yourself. You may try to override upload_tmp_dir
but that’s very often not possible.
However, as this is part of the server configuration set up by your provider, it shouldn’t be broken all that often. What’s possible, though, is that somebody (most likely you) messed with the temporary folder, so even though the config is correct, the folder is not (in my case, I accidentally deleted it). So the first step for you is to check what the temp directory is and whether it exists and is writable.
Now regarding WP_TEMP_DIR
: This seems to have helped a lot of people, judging from the search results. TBH, given what I wrote above, I have no idea why WP_TEMP_DIR
should be relevant for file uploads. It’s possible that WordPress does additional postprocessing (resizing images…) for which it needs its own temporary folder.