嗨我想从嵌入字段获取文件路径,使用该路径查看文件是否存在于该路径中。如果文件不存在,则删除该条目。我正在运行一个游戏网站,下载游戏文件的脚本跳过了一些,所以它就像在4000条记录的数据库中找到针一样。任何帮助表示赞赏。这里是我的代码:使用文件检查器搜索和删除数据库行
<?php
if(isset($_POST['clean'])) {
$query = "SELECT * FROM games WHERE embed";
$result = mysql_query($query) or die ("no query");
$result_array_path = array();
while($row = mysql_fetch_assoc($result))
{
$result_array_path = $row;
}
$count = mysql_num_rows($result);
for($counter=0;$counter<$count;$counter++){
if (file_exists($result_array_path[$counter])){
}else{
mysql_query("DELETE FROM games WHERE embed".$result_array_path[$counter]);
echo $result_array_path[$counter]." ";
}
}
}
?>
--------------编辑-------------
我更新的代码BUT它决定删除我的整个数据库,而不是删除缺少的游戏条目。下面是修改后的代码:
<?php
if(isset($_POST['clean'])) {
$query = "SELECT * FROM games WHERE embed NOT LIKE '%mochiads.com%'";
$result = mysql_query($query) or die ("no query");
$result_array_path = array();
while($row = mysql_fetch_assoc($result))
{
$result_array_path[] = $row['embed'];
}
foreach($result_array_path as $path) {
if(!file_exists($path)) {
mysql_query("DELETE FROM games WHERE embed = '" . $path . "'");
echo $path." | ";
}
}
}
?>
----------- --------------编辑
我调试的程序,所以它的工作原理现在。必须在程序中添加“$_SERVER['DOCUMENT_ROOT']
”。这里是完成的程序
<?php
if(isset($_POST['clean'])) {
$query = "SELECT * FROM games WHERE embed NOT LIKE '%mochiads.com%'";
$result = mysql_query($query) or die ("no query");
$result_array_path = array();
while($row = mysql_fetch_assoc($result))
{
$result_array_path[] = $row['embed'];
}
foreach($result_array_path as $path) {
$rel_path = str_replace('http://www.flamegame.net', '', $path);
$rel_path = str_replace('http://flamegame.net', '', $rel_path);
$rel_path = str_replace('%20', ' ', $rel_path);
if(! file_exists($_SERVER['DOCUMENT_ROOT'] . $rel_path)) {
mysql_query("DELETE FROM games WHERE embed = '" . $path . "'");
echo $rel_path." | ";
}
}
}
?>
谢谢所有的帮助特别是加格龙。
对于那些谁不知道这个节目是我的网站: http://www.FlameGame.net
你得到的输出是什么? – Achrome 2013-02-10 22:24:29
什么都没有 - 页面只是重新加载没有输出 – user2030325 2013-02-10 22:31:33