私はこれでいくつかの助けを使うことができます. 1 つのディレクトリからファイルのリストを取得し、それらを配列として返す必要がありますが、キーは値と同じである必要があるため、出力は次のようになります。
array(
'file1.png' => 'file1.png',
'file2.png' => 'file2.png',
'file3.png' => 'file3.png'
)
私はこのコードを見つけました:
function images($directory) {
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// open directory and walk through the filenames
while ($file = readdir($handler)) {
// if file isn't this directory or its parent, add it to the results
if ($file != "." && $file != "..")
{
$results[] = $file;
}
}
// tidy up: close the handler
closedir($handler);
// done!
return $results;
}
正常に動作していますが、通常の配列を返します。
誰かがこれで私を助けることができますか?
また、最後に小さなメモとして、画像ファイル (png、gif、jpeg) のみをリストする必要があります。