I try to create a php cron job with help of the WP Control plugin. The purpose is to delete all files in the uploads directory for the current year and month.
I use this code:
$files = glob('./wp-content/uploads/' . date('Y') . '/' . date ('m') . '/*'); // get all file names
foreach($files as $file){ // iterate files
chown ($files, 666); //set the permissions
if(is_file($file)){
unlink($file); // delete file
}
It is not working.
When I set the first line of code:
$files = glob('./wp-content/uploads/' . date('Y') . '/' . date ('m') . '/*'); // get all file names
to
$files = glob('./wp-content/uploads/2019/01/*'); // get all file names`
it works.
What am I missing here?