PHP Code Snippet

Occasionally you will try and install a new plugin on a fresh install of WordPress, and come a cropper with an error that returns ‘Download failed. Destination directory for file streaming does not exist or is not writable.

Download-failed
 
This is usually caused by incorrect permissions in the wp-content folder, as WordPress needs to create a temporary folder to put the files when downloaded, before install.

Rather than using 777 permissions to allow WordPress to create the correct folder, and then having to reverse the permissions and potentially creating a security hole, we will put a temporary folder outside of the install directory. In other words, find the root folder and go up a directory. As we are now outside of the public directory, we can now create a folder called ‘temp’ with 777 permissions and not create a security hole.

Once you have done this, open up the wp-config.php file in the root directory and add the following at the bottom.

define('WP_TEMP_DIR', ABSPATH . '/../temp/');

Now you’ll see that you won’t have any updating or plugin install issues.