I'm trying to search in a directory some images by offer and then insert them in database. But first, images in directory are many - 35000 and I should search in this directory for all offers - that are 10000. It's showing error:
maximum execution time exceeded in 30 sec
How should I do that?
I'm searching by pattern - by $segment - that is offer id:
if ($dh = opendir($dir))
{
$array = array();
while (($file = readdir($dh)) !== false)
{
$s = substr($file, strpos($file, $segment), strlen($segment));
if($s == $segment) {
$array[] = $file;
}
foreach($array as $key) {
$sql = new sql();
$sql->query("INSERT INTO offers_images(offer_id, offer_filename) Values ('".$segment."', '".$key."') ");
}
closedir($dh);
}
}
</div>