我正在嘗試搜索文件夾並檢索文件夾內的文件(獲取內容)我可以使用以下代碼搜索文件夾但我不能從那裏通過我看不到內容檢索裏面的文件。裏面的文件將是txt文件,我希望能夠打開並看到。 如何才能實現我想要的?謝謝。搜索文件夾並獲取文件內容
<?php
$dirname = "C:\windows";//Directory to search in. *Must have a trailing slash*
$findme = $_POST["search"];
$dir = opendir($dirname);
while(false != ($file = readdir($dir))){//Loop for every item in the directory.
if(($file != ".") and ($file != "..") and ($file != ".DS_Store") and ($file !=
"search.php"))//Exclude these files from the search
{
$pos = stripos($file, $findme);
if ($pos !== false){
$thereisafile = true;//Tell the script something was found.
echo'<a href="' . $dirname . $file . '">' . $file . '</a><br>';
}else{
}
}
}
if (!isset($thereisafile)){
echo "Nothing was found.";//Tell the user nothing was found.
echo '<img src="yourimagehere.jpg"/>';//Display an image, when nothing was found.
}
?>
旁註:''&&的優先級高於'和',所以你可能要使用來代替。 –
'glob()'是一個很好的選擇以及最好的命名的php函數!仍然在等待'溼()' – 2014-01-16 01:29:01