PHP upload temp files not deleting

As you may be aware my blog primarily deals with running Mahara and Moodle on a Windows system and the solutions for challenges I have encountered.  Today’s problem had been happening for a while but I didn’t realised there was a problem for a long while or what was causing it.

The symptoms

My server’s C drive was slowly filling up, in fact I worked out once I  had found the problem and its cause there was approximately 35GB of unwanted data on the drive.  I knew it wasn’t the web root, backups or Moodle and Mahara data as these are located on other drives.  Basically the C drive is only for running Windows server and associated applications.

I’m not sure if this stuff is common knowledge to others but I really had no idea what was causing the excessive drive usage.  I cleaned out my SAML logs (there’s a whole ‘nother story) but that made little difference. I did a search of the drive for ‘gigantic’ (greater than 128MB) and found the C:/Windows/Temp drive had thousands of temp files of varying size.  These all had file names starting with php…

The cause

Turns out these files are uploaded in the Windows Temp directory (as per the settings in my php.ini file) until they are fully uploaded then copied to their required location.  Once the process is complete the temporary file is deleted; however, in my case they were not and an unnecessary copy of every file uploaded remained in the temp directory.

The solution

I did some research into the problem and found very little in the way of solutions.  some of the solutions I tested didn’t work.  I realised it was a permissions problem the solutions were suggesting changed to accounts that made no difference.  I worked out the correct account and the lowest amount of permissions required to fix the problem.

So it’s an easy fix, just change your IIS_IUSRS permissions to modify and below for your temp drive.

temp files

 

temp files2
Don’t forget to delete those old temp files

 

One thought on “PHP upload temp files not deleting

Leave a comment