code to achieve the function is to query the uploaded directory under the picture in the database if not deleted, I wrote the code as follows, in the local test when the picture is relatively few can be uploaded to the server, because the server has more pictures, the database is also relatively large, the execution has been shown "waiting for www.abc.com response". I would like to ask the boss how to modify the code can be used in a large multi-picture database?
<?php
set_time_limit (0);
header("Content-type: text/html; charset=utf-8");
$_config = array();//
// ---------------------------- CONFIG DB ----------------------------- //
$_config["dbhost"] = "127.0.0.1";
$_config["dbuser"] = "root";
$_config["dbpw"] = "root";
$_config["dbname"] = "dbname";
$_config["table"] = "pic";//
$_config["url"] = "pic_url";//
$link = mysqli_connect($_config["dbhost"], $_config["dbuser"], $_config["dbpw"]);
if (!$link){
exit("");
}
mysqli_set_charset($link, "utf8");
mysqli_select_db($link, $_config["dbname"]);
//
$arr=glob("upload/pic/*/*.{jpg,png,gif,jpeg}",GLOB_BRACE);//*
if(count($arr)>0){
$j=count($arr);
$ndel=0;
for($i=0;$i<$j;$iPP){
$sql="select ".$_config["url"]." from ".$_config["table"]." where ".$_config["url"]." like "%$arr[$i]%"";
$myrun = mysqli_query($link, $sql);
echo ($sql."<br>");
if(!mysqli_num_rows($myrun)){
echo "$arr[$i]......<br><br>";
unlink ($arr[$i]);
$ndelPP;
}
$n=count($arr)-$ndel;
echo "<center><div style="margin-top:50px; line-height:25px; font-size:15px; color:-sharp3399FF;">";
if($ndel>0){echo "<font color="-sharpff0000"> ".$ndel." </font>";}
echo "<font color="-sharpff0000"> ".$n." </font></div></center>";
}
if(count($arr)==0){
echo ("");
}
mysqli_close($link);
?>