[英]How to link up files from grandchild directory down two levels from the current dir with PHP opendir?
I cannot seem to get the links that are populated from the directory scan to LINK up appropriately. 我似乎无法使目录扫描中填充的链接正确链接起来。 When I click the populated link it is currently referencing the current directory instead of the grandchild directory here dir_2/dir_3. 当我单击填充的链接时,它当前引用的是当前目录,而不是此处的孙目录dir_2 / dir_3。 Any help would be very appreciated. 任何帮助将不胜感激。
<?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('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);
}
?>
You need to append the directory you're looking at to the link. 您需要将要查看的目录附加到链接。
$dir = 'dir_2/dir_3';
if ($handle = opendir($dir)) {
// snip
print("<a href=\"".$dir.$file."\">".$file."</a><br />\n");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.