Deleting a file that does not exist in the database sometimes does not record this file in the database, but it still exists in the folder. how can I use php to write a piece of code, after the execution, the ------ solution -------------------- foreach (glob (directory *) & nbsp; as & nbsp; $ f) & nbsp ;{& nbsp; & nbsp; $ rs & nbsp; mysql_quer delete files that do not exist in the database
Sometimes, this file is not recorded in the database, but it still exists in the folder. how to use php to write a piece of code will delete these files after execution?
------ Solution --------------------
Foreach (glob ('directory/*) as $ f ){
$ Rs = mysql_query ("select * from table where field = '$ f '");
If (! Mysql_num_rows ($ rs) unlink ($ f );
}
------ Solution --------------------
First, write the files in the database to a list.
Then, compile the calendar folder. if the file is not in the list, delete it.