我使用此代碼,以便從目錄中獲取列表文件:PHP - 刪除'。'並且從目錄中的文件獲取值「..」
$dir = '/restosnapp_cms/images/';
if ($dp = opendir($_SERVER['DOCUMENT_ROOT'] . $dir)) {
$files = array();
while (($file = readdir($dp)) !== false) {
if (!is_dir($dir . $file)) {
$files[] = $file;
}
}
closedir($dp);
} else {
exit('Directory not opened.');
}
我想擺脫的價值觀「」和'..'。
是否有可能做到這一點?謝謝。 :)
使用if條件 – frunkad 2015-02-11 20:02:29
當然,您可以在輸出之前對其進行過濾。有許多陣列功能可以幫助這種或那種方式。或者你可以在循環中放一個'if',只輸出不是'.'或'..'的名字。 – GolezTrol 2015-02-11 20:03:43
難道這不容易嗎? '$ files = array_filter(glob(「$ dir/*」),'is_file');' – AbraCadaver 2015-02-11 20:20:51