How to delete files that do not exist in the database

Source: Internet
Author: User
Tags glob
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.