Filed under php , windows server , wordpress
When uploading files in Wordpress, PHP uses a temporary upload folder. By default PHP will use the C:\Windows\Temp when uploading files. If you install PHP and Wordpress onto your Windows server then you might notice that any files uploaded through Wordpress are not accessible on your site. This is down to PHP taking the folder permissions from the C:\Windows\Temp folder which does not have public access granted on it (for obvious security reasons!).
To work around this issue you need to create a new folder and give that folder the correct permissions for the uploaded files to be available to users who visit your site.
Step 1: Create a new folder. I decided to use a folder on the root level: C:\TempUploadedFiles
Step 2: Right click on this folder and grant enough permissions for the files to be viewed online. Typically you would add IIS_IUSR, Users and NetworkService users with read permissions.
Step 3: Now we need to tell PHP to use this new folder when uploading files. Open your PHP.ini file in notepad (usually in C:\Program Files (x86)\PHP) and locate the line with 'upload_tmp_dir'. Replace the whole line with this:
upload_tmp_dir = C:\TempUploadedFiles
(make sure there is no semi colon at the start of the line!)
Gotcha: Be sure to check that there is no other 'upload_tmp_dir' declared in the PHP.ini file. In the file I was using there was another instance of 'upload_tmp_dir' located at the end of the file and it was overwriting my values.
Step 4: Save your PHP.ini file and open IIS. Locate your website and click on restart for the new settings to take effect.
Step 5: Open Wordpress and upload your new file. PHP will use your new destination to handle the file during upload and when the file has fully uploaded it will transfer it to the correct location in your wp-content/public folder with the correct permissions.
You only need to make this change once as in future all PHP sites will use the new C:\TempUploadedFiles folder.