title: check filesystem file consistency against db
body: <p>I have a PHP script that uploads files to a directory on my filesystem. On the same time I store the filename in a field on a MYSQL DB.</p>
  
  <p>I have seen that I have more files than records in the db. </p>
  
  <p>What's the shortest way to find out and delete all those files that are not linked to a record on the DB? My idea would be to read each filename from the directory, run a query on the db with the filename taken from step 1 and in case the query returns 0 result to delete the file.</p>
  
  <p>Thanks in advance for any advice.</p>
  
  <p>Lelio</p>