0

I keep getting many pdf file in my directory root/files/pdfs. I want a PHP script to automatically delete only the .pdf files from the pdfs folder that are older than 24 hours (86400 seconds).

What permissions will the .php file require? Where to put the file? Should I have to run the PHP by visiting the link of the PHP file?

NOTE: I have a FTP access to a subdomain

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Saif
  • 2,530
  • 3
  • 27
  • 45

1 Answers1

1

You can try this method, it checks the file creation time. Or use "filemtime" for file modified time.

$dir = "root/files/pdfs/";   //your folder location

foreach (glob($dir."*.pdf") as $file) { 
    if (filectime($file) < time() - 86400) { 
        unlink($file);
    }
}
nodeffect
  • 1,830
  • 5
  • 25
  • 42