How to change your PHP temp directory

On this blog, I use WordPress since I’m too lazy to code everything myself. Now, the other day, whilst trying to upload an image, I was faced with the infamous “Failed to write to disk” error. A quick Google search brought up the most common causes of this error, being a full server hard drive, incorrect permissions or a full tmp folder.

I knew the problem wasn’t with the hard drive since I was able to upload all my data via FTP. I also knew that it wasn’t a permission problem since everything was working perfectly a few minutes ago, and my permissions hadn’t changed.

So the problem was probably with the tmp folder… I decided to contact my host’s (Awardspace) customer support, and explained the problem. They replied within a few minutes with a nice little fix that I thought I’d share with you.

What you need to do is open your PHP.ini file (you should be able to access this via your hosting tools) and search for the following code, if you can’t find it, simply add it to the end of the file. Also, if the line is preceded my a semicolon ( ; ), remove it:

upload_tmp_dir = “some directory”

In this case, “some directory” will probably be ‘tmp’ or something similar. What you want to do is change this line to a custom folder, as such:

upload_tmp_dir = /home/www/yourdomain.com/foldername

Where yourdomain is your website address and foldername is the name of the folder you wish to use as the PHP temp directory.

Once you’ve added this line of code, you’ll need to create a folder in your website’s root directory with the same name as the one specified previously. I also recommend you set this folder’s permissions to 755 (777 works, but is ridiculously unsafe).

That’s how you change your PHP temp directory on shared hosting. Note that it might take some time for the changes to take effect.

Thank’s for reading!
-Icosebyte