[Resolved] Deleting file that corresponds to the ID in the d

admin

Administrator
Staff member
Let's say I have the following records in mySQL database. ID, name, adress, phone_number. I also have images that correspond to to the record IDs. (For example: if records ID 12345 corresponding image is 12345.jpg)

From time to time I delete records from my database, but image file stays on the server. So what I want to do is search through all the records in the database and compare it to the existent files. If ID in the database matches the file on the server I don't want to do anything, if there is a file on the server, but there is no corresponding record (ID), I want to delete that file and finally if there is record in the database but there is no corresponding file, I want to list those records (IDs) on the page.

I would really appreciate if anybody would help me with this.
 
Top