How To Fix WordPress Upload Failed To Write File To Disk Error?

4 (80%) 1 vote

How to fix Upload Failed to Write File to Disk error in wordpress

WordPress Upload Failed To Write File To Disk

Trying to upload an image but WordPress failed to upload due to an error “failed to write file to disk”? This is a common error which pops up while uploading media in posts/pages. File permission such Read, Write and Execute allows or deny you to upload images, videos or files to your website. An incorrect permission may cause the “Upload: failed to write file to disk” error in WordPress.

This error can occur for several reasons. such as incorrect permissions to the folder.

You will see that in most cases it is not necessary to change these permissions, because either your hosting server or WordPress itself already load them correctly, but it is not always the case.

You can change the permissions of the specific folder or file by using any plugin or FTP client, but always remember that you are leaving a possible security hole.

Actually changing file and folder permissions is simpler than it seems, and it can fix Upload: failed to write file to disk in your WordPress.

In this article, we will talk about how to fix “Upload: Failed to Write File to Disk” error in WordPress by setting the correct permissions, but as usual, we will try to make it as simple as possible explaining the cause of this error.

However, it may not be a bad idea to scan your WordPress website for malware here. It’s better to err on the side of caution than to be at the mercy of an attack. Learn more about how to protect your website with these WordPress Security Tips 2019.

Do you keep your WordPress protected with security plugins? If no, then look out for these best wordpress security plugins. What kind of other common WordPress errors have you come across in WordPress? Are they any of these –

What Causes failed to write file to disk error in WordPress?

If you have received an error message failed to write file to disk, keep in mind that this is an access problem. The error message directly indicates the wrong permission settings. Such error can be very frustrating for users that compromise the integrity and control over database.

Each file and folder on your website has a set of permissions. Your web server controls access to files based on these permissions.

Incorrect File and Folder Permissions in WordPress may prevent the ability to write files to the disk. This means that your web server cannot create or add new files to this particular folder. Incorrect permissions can also compromise security of your WordPress site.

This error can occur for several reasons. However, the most common are incorrect permissions to the folder. One of the most important elements when it comes to fixing failed to write file error in WordPress is the permissions of files and folders, and the basic rule in WordPress would be the following:

  • 644 for files

  • 755 for folders

You will see that in most cases it is not necessary to change these permissions, because either your hosting server or WordPress itself already load them correctly, but it is not always the case.

So it does not hurt to check the permissions of your installation and follow the basic rule that we have noted before. You can change the permissions of the specific folder or file by using any plugin or FTP client, but always remember that you are leaving a possible security hole.

Steps to Fix failed to write file to disk error WordPress

In these cases, it measures the decision well, because sometimes it is better to switch to a plugin that offers the same without that ” peculiarity ” than to leave a possible space for hacker entry.

If you want to check file permissions, some options are:

  1.  File Manager of your hosting, where you can browse folders and there is always a link or button to change folder permissions.

  2.  FTP client such as Filezilla, in which right-clicking on any file or folder you can change the permissions or access the information window of the above and change them.

Actually changing file and folder permissions is simpler than it seems, and it can fix Upload: failed to write file to disk tin your WordPress.

How to fix WordPress upload “failed to write file to disk” Error?

WordPress Upload Failed To Write File To Disk

First, you need to connect to your WordPress site using an FTP client.

For this tutorial, we can use FileZilla free FTP client. If you use another FTP client, it may be a little different but it depends on you to decide.

Once connected, right-click on the wp-content folder and select the file permissions.

This will open the file permissions dialog box in your FTP client. It will show you file permissions for the owner, group, and everyone.

file permissions WordPress Upload Failed To Write File To Disk

>>You must enter 755 in the field.

>>After that, check the box next to “Recurse Subdirectories”.

Finally, you must click on the option “Apply only to directories”.

>>Click the OK button to continue.

Your FTP client will now configure folder permissions in 755 and apply it to all wp-content subfolders. This includes the download folder where all your images are stored.

You also want to make sure that the individual file permissions in your wp-content folder are appropriate.

>>Once again, right-click the wp-content folder and select the file permissions. This time we will change the permissions for the files.

>>Enter 644 in the numeric value, then check the “Use subdirectories” box.

Finally, you have to click on the option “Apply only to files”.

>>Click the OK button to continue. Your FTP client will now set file permissions to 644 for all files in the wp-content folder.

Now you can visit your WordPress site and try to download files.

If the error persists, get in touch with your WordPress hosting provider and ask them to empty the temporary files directory.

WordPress uploads your images using PHP, which first “download” the downloads to a temporary directory on your web server. After that, move them to your WordPress download folder.

If this temporary directory is full or incorrectly configured, WordPress cannot write the file to disk.

This temporary folder is located on your server and, in most cases, you cannot access it via FTP. You must contact your host and ask them to empty it for you. 

Empty the Temporary File Directory

It is possible that you have been in the situation of not being able to write an image or any other file to your disk from WordPress. It may be that the hosting in which your WordPress is hosted has limited access to that directory, so in that case, there will be tasks that WordPress cannot perform.

To avoid relying on the /tmp directory, we will create a directory and have WordPress execute the temporary files there.

Note: We will perform the guide using the terminal, but you can follow it without having an SSH terminal or connection. In that case, you will have to use the tools available to perform the same steps.

First, we will create the directory. You can call it what you want, although for example, we have called it tmp to associate it with the temporary directory. Go to the directory where WordPress is installed with the command cd $ DIRECTORY_WP and then create the directory mkdir $ TMP_DIR.

The $ WP DIRECTORY variable is the path to the directory in which WordPress is installed, and $ TMP_DIR is the name of the temporary directory.

Create a temporary folder

The directory you created must have the correct permissions. These permissions will depend on your website, although the most common are 775 or 755. Now, we are going to tell WordPress that you should use that directory as a temporary directory.

  • Edit the file wp-config.php

  • Enter the directive define (‘WP_TEMP_DIR’, ‘$ DIRECTORY_WP / $ TMP_DIR’)

  • Replace $ DIRECTORY_WP and $ TMP_DIR with the path to the directory where you have WordPress installed and the name of the directory (or folder) you created to be the WordPress temporary directory

Indicate the temporary folder in wp-config.php

It is possible that after doing this you still cannot upload files to your WordPress. This is because PHP also does not have a temporary directory in which to run. We will take advantage and make php use the same directory we just created.

If your website is using PHP-FPM, simply enter the following directives in the pool you are running.

  • env [TMP] = $ WP_DIRECTORY / $ TMP_DIR

  • env [TMPDIR] = $ WP_Directory / $ TMP_DIR

  •  env [TEMP] = $ WP_DIRECTORY / $ TMP_DIR

Replace the variables mentioned above with the corresponding values, and restart the version of PHP-FPM your WordPress is using. Note: If you use a pool for several domains, it is preferable to create a directory outside the domains and make the temporary PHP-FPM files run there.

  •  Indicate the temporary folder in PHP-FPM

  •  Now we can successfully write file to disk

If after this, you still have “upload failed to write file to disk” error, contact your hosting, because the error must be at the system level.

Change the permissions with an FTP client

Here, we show you how to change the permissions of files and folders (directories) on your WordPress with an FTP client.

By setting file permissions, you determine who reads, writes, and executes. If the permissions are too strict, the elements of your site will stop working. If permissions are too flexible, anyone can do anything, which is not secure.

We use FileZilla as an FTP client, and we connect with SFTP instead of FTP because it is encrypted and more secure. If you use another client, things will be slightly different.

You must connect to your FTP with FileZilla. Enter the host (ftp.domain.com or server IP address), your user (the same user as your cPanel account) and your password (the same password as your cPanel account).

Right-click on the directory where you want to recursively modify the rights and click on ”File permissions”.

Open FileZilla and enter the following login details, replacing your-domain.com with your own domain:

Hosting: ssh.your-domain.com (or ftp.your-domain.com for FTP)

Username: your-domain.com

Password: the password you have chosen for SFTP (or FTP)

Port: 22 (or 21 for FTP)

Select All Files and Folders

  • You must select all the files and folders for which you want to set permissions. In most cases, you can select them all by one click.

  • Then right-click on the selected folders and choose File Permissions from the menu that appears.

We must first set the permissions for the files.

  • For Numeric Value, enter 644.

  • Check the Recursive box in the subdirectories.

  • Select the option “Apply to files only”.

Modify folder and file permissions in cPanel

To change permissions in a simple and basic way from FTP, ssh, cPanel, etc. Read the following instructions –

One of the simple and basic ways to change permissions is through File Manager in cPanel. To change the permissions for a file or folder in cPanel, do the following:

  1. Enter your cPanel.

  2. Click File Manager.

  3. Click the name of the file for which you want to change the permissions.

  4. Select the link change permissions at the top right of the page.

  5. Select the permissions you want to set for the file.

  6. Click Change permissions.

Modify Permissions using FTP

  1. You will have to connect via FTP. (Example Filezilla client).

  2. Select the file or folder and right-click.

  3. Click “File permissions” and we can make the modification (it depends on your program, but the process is usually similar).

 fix Failed to Write File to Disk error WordPress incorrect permissions ftp client

Checking Quota Limit

Another cause for Failed to Write File to Disk WordPress error can be your hosting. Thus contrary to popular belief, exceeding the quota limit of your hosting can be helpful in this regard. The bandwidth assumes the maximum flow of data that can be sent through the line.

It is defined in Megas (for now) and assumes the amount of data that can be transmitted per second. As in our homes, we have a bandwidth of 20 megabytes, the server also has its own specific bandwidth.

Imagine a river. This river has a certain width, in addition to a flow of water that flows continuously. We could assimilate the river’s width with the bandwidth and the water flow with the data transfer.

Thus, we will have to adapt our bandwidth to the flow of data that reach us, and, only in the case that we had too much flow, consider increasing our bandwidth.

The cause for Failed to Write File to Disk error is if your website has exceeded the space limit of the web hosting service. Opt for hosting that provides unlimited space, but many other hosting providers set pretty low limits.

Access your file permissions

Another possible cause of this problem is the incorrect configuration of file permissions. There are several factors to consider to ensure that your file permissions are correct. Next, we explain two simple ways to resolve Upload: failed to write file to disk” error in WordPress.

It is related to your web hosting plan, just go to the section Others> Correct ownership of files in the cPanel. With just one click, the tool will locate and repair any file or directory with permission issues.

Another option to do the same task is via FTP:

  • Open your File Transfer Protocol (FTP) client.

  • Enter your host details in the relevant fields.

  • Then, go to public_html within that folder.

  • You will have to highlight the subfolders called wp-admin, wp-content and wp-includes.

  • Then, select File Permissions.

In the Change file attributes window that appears, you must ensure that the numerical value is 755, the repeat in subdirectories box is checked and Apply only to selected directories:

 Change-wp-config-folder Permissions-Filezilla

Select OK to apply any changes. Then, return to public_html and select all the files within the folder. Be sure to exclude the three directories that you have already modified. You must right-click on the files and select File Permissions once again:

 Change-File-Permissions-public_html-FileZilla

In the next Change file attributes window, verify that the numerical value is 644, the Repeat in subdirectories box is checked and Apply only to selected files. Then, press OK:

  change-file-attribute-window-set-to-apply-to-files-only

This process should resolve upload failed to write file to disk error in WordPress. Also, ensure that the basic permissions for your WordPress files are set correctly. To summarize, directory permissions must be 0755, while file permissions must be 0644.

Contact your Web Hosting Provider

If after changing the files permissions you are still having this error; it could simply be that you have to contact your web hosting provider to help then about emptying your temporary file directory. So if your temporary directory is full or not configured correctly; this will make it that we cannot write the file to the disk which will then cause the error to happen. So again you may simply have to contact your web hosting provider if this simple fixes did not work for you.

Conclusion

In this tutorial, we saw how to fix Upload: Failed to Write File to Disk error in WordPress. We hope this guide has been able to help you keep writing the files and multimedia content to your disk from WordPress website.

Be sure to check out our other WordPress tutorials for quick fixes to WP errors, however for any questions, do not hesitate to contact us for any type of WordPress related technical services.

Best WordPress Security Service

Leave a Reply

Your email address will not be published. Required fields are marked *