Calculate folder and subfolders size with PHP

How to read the size of a directory using PHP? Here is a simple function which could help read the size of the directory, number of directories and the number of files in the given directory.