• joshclicky

    (@joshclicky)


    A few weeks ago our website started giving the following error message when trying to upload an image to the WordPress Media Library.

    “filename” has failed to upload.
    Missing a temporary folder

    No change were made the the WordPress code, theme, or plugins prior to this issue occurring.

    After doing some research we found two potential fixes for the problem which we have tried but unfortunately did not resolve the problem.

    Fix 1: Created a folder named ‘temp’ in the wp-content folder with permissions set to 777, and added the following line to the wp-config.php file:

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

    Fix 2: Created a folder named ‘temp’ in the directory root with permissions set to 777, added the following line to our php.ini file in the directory root:

    upload_tmp_dir= your/path/to/public_html/temp/

    We created a subdomain on our server, spun up a fresh install of WordPress using the out of the box theme/plugins, and still proceeded to get the issue when uploading images.

    Has anyone else experienced this issue before, have a resolution, or able to suggest what we could try next?

    Thanks in advance.

    • This topic was modified 3 years ago by joshclicky.
    • This topic was modified 3 years ago by joshclicky.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    The PHP temp folder is a system setting that’s defined in php.ini. It defaults to /tmp but is normally altered by your host for shared hosting. You can determine the current expected location by adding
    <?php echo "\nTemp directory: ", sys_get_temp_dir(), "\n"; ?>
    to a theme template file, then viewing a page that uses the template.

    In any case you’ll likely need your host’s assistance to rectify this.

    Thread Starter joshclicky

    (@joshclicky)

    Thanks for the response @bcworkz.

    I carried out your suggestion which initially returned the following path:
    /home/ftpuser/public_html/wp-content/temp

    However, we still had the following line in the wp-config.php:
    define(‘WP_TEMP_DIR’, dirname(__FILE__) . ‘/wp-content/temp/’);

    After removing the above line from the wp-config.php, we refreshed the page we were echoing the temp folder directory too, but it was just coming back empty.

    On that basis I assume the issue would be that the line to define the temp folder is missing from our php.ini?

    Moderator bcworkz

    (@bcworkz)

    It’s possible to be empty in php.ini, but then the default folder /tmp would normally be used. Thus sys_get_temp_dir() should then return “/tmp”. I’ve not encountered an empty return value before, so I’m unsure what that means.

    In any case, PHP saying “Missing a temporary folder” indicates a server configuration issue where you’ll need your host to help rectify. That is unless you have a VPS and access to its php.ini. In that case you can add something like sys_temp_dir = "/path/to/an/existing/folder" to the file and restart Apache.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Unable to upload to Media Library’ is closed to new replies.