by Davo Smith.
I had a quick glance at the code - most of it looks reasonable, but I'd really avoid using DB queries to search through the 'files' table. In the case you showed, $fs->get_area_files(...) would be far more appropriate.