Delete Files Older than n Number Of days Using PHP?

Some times in application development, we required to delete files older than specified number of days. Actually below method removes older files from disk and free the hard disk memory.

Below example demonstrate how to delete files, older than specified number of days. This code delete files from specified directory only, not from child folders. deleteOldFiles() method takes three parameters first one is folder/directory path, second one is number of days and third parameter is return count.

Simple Method to Delete Files Older than n Number Of days

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.