我似乎無法使粗體文件路徑工作。我希望腳本掃描Dir_3。任何幫助將非常感激。如何用PHP opendir讀取當前目錄之外的目錄?
<?php
// These files will be ignored
$excludedFiles = array (
'excludeMe.file',
'excludeMeAs.well'
);
// These file extensions will be ignored
$excludedExtensions = array (
'html',
'xslt',
'htm',
'ahk',
'xsl',
'txt',
'xml'
);
// Make sure we ignore . and ..
$excludedFiles = array_merge($excludedFiles,array('.','..'));
// Convert to lower case so we are not case-sensitive
for ($i = 0; isset($excludedFiles[$i]); $i++) $excludedFiles[$i] =
strtolower(ltrim($excludedFiles[$i],'.'));
for ($i = 0; isset($excludedExtensions[$i]); $i++) $excludedExtensions[$i] =
strtolower($excludedExtensions[$i]);
// Loop through directory
$count = 0;
if ($handle = opendir('**http://www.mydomain.com/Dir_1/Dir_2/Dir_3/**')) {
while (false !== ($file = readdir($handle))) {
$extn = explode('.',$file);
$extn = array_pop($extn);
// Only echo links for files that don't match our rules
if (!in_array(strtolower($file),$excludedFiles) &&
!in_array(strtolower($extn),$excludedExtensions)) {
$count++;
print("<a href=\"".$file."\">".$file."</a><br />\n");
}
}
echo '<br /><br /><a href="..">Return</a>';
closedir($handle);
}
?>
偉大的幫助了很多。非常感謝你。現在唯一的問題是它在頁面上吐出的鏈接沒有正確鏈接。我是否必須在其他地方調整路徑才能正確連接? – mikenichols
那麼,基於Web的路徑可能與文件系統上的路徑完全不同。 opendir()/ fopen()/ etc的作用可能與這些目錄在網站中的映射方式完全沒有關係。 –