Skip to content
Advertisement

Php – Delete files older than 7 days for multiple folders

i would like to create a PHP script that delete files from multiple folders/paths. I managed something but I would like to adapt this code for more specific folders.

This is the code:

JavaScript

I would like to make something like to add more paths and this function to run for every path. I tried to add multiple path locations but it didn’t work because it always takes the last $ path variable. For exemple:

JavaScript

Thank you for you help!

Advertisement

Answer

The simple solution, call the function after setting the parameter not after setting all the possible parameters into a scalar variable.

JavaScript

Alternatively, place the directories in an array and then call the funtion from within a foreach loop.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement