我試圖創建一個目錄中的文件列表,包括子目錄中的文件,顯示其完整路徑,文件名和擴展名。任何指導將不勝感激。如何查看數組中的值?
大量閱讀後,我嘗試了幾件事情,這是最近我發現並嘗試過,但沒有任何喜悅,現在我只是尋找瀏覽器來顯示上述信息。
$dir = '../test/images/';
function getFileList($dir, $recurse=false)
{
// array to hold return value
$retval = array();
// add trailing slash if missing
if(substr($dir, -1) != "/") $dir .= "/";
// open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
// skip hidden files
if($entry[0] == ".") continue;
if(is_dir("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry/",
"type" => filetype("$dir$entry"),
"size" => 0,
"lastmod" => filemtime("$dir$entry")
);
if($recurse && is_readable("$dir$entry/")) {
$retval = array_merge($retval, getFileList("$dir$entry/", true));
}
} elseif(is_readable("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry",
"type" => mime_content_type("$dir$entry"),
"size" => filesize("$dir$entry"),
"lastmod" => filemtime("$dir$entry")
);
}
}
$d->close();
return $retval;
}
print_r($retval);
我的最終目標是創建一些PHP上執行將查找的目錄,創建子目錄(有任何子目錄中)具有相同名稱在新目錄中(所以/測試/相冊/會被創建爲/ live/album /)。然後調整每個原始目錄中包含的任何圖像的大小,並將其保存到其相關的新目錄中。我很欣賞這是很多的,並且毫無疑問在我繼續時會有很多問題,但會在以後保存這些問題。
幹得漂亮! +1是爲了進入OP的問題的根源。 :) – Herbert
由於不太熟悉PHP,我需要花一些時間來解決這個問題,但是想要感謝你對這個問題的廣泛建議。 – dajoto
我得到一個錯誤'致命的錯誤:調用未定義函數mime_content_type()'任何想法,爲什麼這可能是? – dajoto