$my_array = array(); $dir = opendir ("/var/www/html/uploads"); while (false !== ($file = readdir($dir))) { if (strpos($file, '.txt',1)||strpos($file, '.txt',1) ) { $my_array[] = $file; echo ''; } }