11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 10 • WORKING WITH THE FILE AND OPERATING SYSTEMwww.it-ebooks.infoThis returns the following:Partition: /usr (Allocated: 36716.00 MB. Used: 32327.61 MB.)Retrieving a Directory Size<strong>PHP</strong> doesn’t currently offer a standard function for retrieving the total size of a directory, a task moreoften required than retrieving total disk space (see disk_total_space() in the previous section). Andalthough you could make a system-level call to du using exec() or system() (both of which areintroduced in the later section “<strong>PHP</strong>’s Program Execution Functions”), such functions are often disabledfor security reasons. An alternative solution is to write a custom <strong>PHP</strong> function that is capable of carryingout this task. A recursive function seems particularly well-suited for this task. One possible variation isoffered in Listing 10-1.■ Note The Unix du command will summarize disk usage of a file or a directory. See the appropriate manual pagefor usage information.Listing 10-1. Determining the Size of a Directory’s Contents

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!