Merhaba, klasördeki dosyayı search form ile aratmaya çalışıyorum fakat handle döngüsünde problem yaşıyorum

<?php
$dizin = "/pdf";
$search_key = $_GET['q']; 
echo '<div class="title">'; if($search_key != "") { echo '"<b><i>'.$search_key.'</i></b>" ile ilgili sonuçlar:'; } else { echo 'Tüm dosyalar:'; } echo '</div>';
if ($handle = opendir("$dizin") or die ("Dizin acilamadi!")) {
while (false !== ($file = opendir($handle))) {
$search_word = preg_match("/$search_key/i", "$file");
if(is_file($dizin."/".$file) && $search_word) {
$filename = str_replace("/$search_key/i","<i><b>$search_key</b></i>",$file);
$class = ($css % 2) ? "satir1" : "satir2";
echo '<div class="'.$class.'"><a href="'.$dizin.'/'.$file.'">'.$filename.'</a> </div>';
$css++;
}
}
closedir($handle);
}
echo '<form method="get" action="search.php">
* * <input type="text" name="q" size="10">
* * <input type="submit" value="Ara">
* * </form>';
?>
yardımcı olabilecek var mı ?