2

画像のフォルダをスキャンしようとしていますが、Macが作成した._ファイルが表示され続けます

私はこのコードを使用しています:

   <?php
if ($handle = opendir('assets/automotive')) {
    $ignore = array( 'cgi-bin', '.', '..','._' );
    while (false !== ($file = readdir($handle))) {
        if ( !in_array($file,$ignore)) {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>

理由について何かアイデアはありますか?それをカバーするignore配列を作成しました。

更新:まだ両方を表示します。

4

3 に答える 3

7

ファイル名だけでなく、ドット (.)で始まるファイルは無視したいと思います。

<?php
if ($handle = opendir('assets/automotive')) {
    $ignore = array( 'cgi-bin', '.', '..','._' );
    while (false !== ($file = readdir($handle))) {
        if (!in_array($file,$ignore) and substr($file, 0, 1) != '.') {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>
于 2011-03-29T20:12:48.327 に答える
2

in_array() 検索したいものと検索する配列の2つのパラメータを取ります。

if ( !in_array($file, $ignore))
于 2011-03-29T20:08:02.143 に答える
0

をチェックしていますin_arrayが、次の質問は「in_arrayは何ですか」です。

in_array には、$file探すために 2 番目のパラメーター (この場合は ) が必要です。あなたは必要になるでしょう:

in_array($file,$ignore);
于 2011-03-29T20:08:24.847 に答える