我正在嘗試創建一個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