From the course: PHP Tips, Tricks, and Techniques

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Select files for archiving

Select files for archiving

- [Instructor] Hi, I'm David Powers, and welcome to this week's edition of "PHP Tips, Tricks, and Techniques", designed to help you become a smarter, more productive PHP developer. Generating a list of files in a directory is a very basic operation in PHP, this script uses scandir to return an array of file names, and then displays them in a for each loop, and we've got the results over here. It's fine if you just want to inspect the contents of a directory. By the way, these dots up here at the top represent the current and parent directories, but a list of files like this isn't much use on it's own. You normally want to do something with the files, for instance you might want to check the size of the files, to see if they need optimizing. Another option would be to check how old the files are, with a view to archiving them. I'm sure you can think of other uses, but let's take that last example, selecting files for archiving, or deletion. In my testing environment, I've gathered a…

Contents