删除数据库中不存在的文件解决思路

WBOY
Release: 2016-06-13 12:01:10
Original
1688 people have browsed it

删除数据库中不存在的文件
有时候,数据库中没有记录这个文件了,可是文件夹中还有存在,怎么用php写一段代码,执行了之后就会删除这些文件的
------解决方案--------------------

foreach(glob('目录/*) as $f) {<br />  $rs = mysql_query("select * from 表 where 字段='$f'");<br />  if(! mysql_num_rows($rs)) unlink($f);<br />}
Copy after login

------解决方案--------------------
首先将数据库中存在的文件写到一个列表
然后编历文件夹,当文件在列表中则不处理,如不在列表中,则执行删除动作。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template