-3

ドキュメント ルートにメモ帳/テキスト ファイルを保存しました。ファイルをデータベースに保存しませんでした。ファイルのファイル名を取得して順番に表示する方法を教えてください。ありがとう

4

3 に答える 3

2

file_get_contents関数のようなものを試しましたか?次のようなことをしたいようですhttp://php.net/manual/en/function.file-get-contents.php ファイルの内容を表示したい場合は、次のように呼び出します。

$file = file_get_contents('/people.txt', FILE_USE_INCLUDE_PATH);
于 2013-04-13T02:02:43.423 に答える
1
<?php
$txtFiles = glob("*.txt")
?>

<html>
 <ul>
  <?php foreach ( $txtFiles as $fileName ) { ?>
  <li><?php echo $filename ?></li>
  <?php } ?>
 </ul>
</html>

http://php.net/glob を確認してください

于 2013-04-13T02:04:11.523 に答える
1

このコード

<?php
if ($directory = opendir('/')) { // if the dir can be opened
    while (false !== ($filename = readdir($directory))) {
        echo "$filename\n"; //printing file names
    }
    closedir($directory);
}
?>

( http://php.net/manual/en/function.readdir.phpから)

ファイルの順不同リストが表示されます。注文したことを示すために。配列に入れてから並べ替えることができます。

ただし、ファイル名を含むテキスト ファイルがある場合は、file_get_contents( http://php.net/manual/en/function.file-get-contents.php ) を使用し、それを配列に入れて並べ替えます。

于 2013-04-13T02:02:27.357 に答える