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.
I have seen that I have more files than records in the db.
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.
Thanks in advance for any advice.
Lelio