我正在尝试创建一个Intranet页面,该页面查找UNC路径中的所有pdf文档,并将它们作为在新窗口中打开的超链接返回列表。我快到了,但是下面的代码显示了完整的UNC路径 - 我的问题如何显示只有文件名(最好不带.pdf扩展名)。我已经尝试了基本名称函数,但似乎无法得到正确的结果。PHP仅提取UNC路径中的文件名
//path to Network Share
$uncpath = "//myserver/adirectory/personnel/";
//get all files with a .pdf extension.
$files = glob($uncpath . "*.pdf");
//print each file name
foreach ($files as $file)
{
echo "<a target=_blank href='File:///$file'>$file</a><br>";
}
的链接正常工作,它只是显示文本显示//myserver/adirectory/personnel/document.pdf
而不仅仅是document
。请注意,上述代码取自我在研究中发现的另一个示例。如果有更好的方法,那么我会接受建议。
您正在寻找为['basename'](http://php.net/basename)。 – Jon 2012-04-25 09:05:51
[如何从PHP的完整路径获取文件名?](http://stackoverflow.com/questions/1418193/how-to-get-file-name-from-full-path-with-php) – 2015-09-04 18:10:48