ディレクトリに設置してあるフォルダをPHPで調べて表示
2024/04/18
やりたい事はsampleというディレクトリがあったとして、その直下にあるフォルダを全部調べて出力させたいというもの。以下に対応方法をメモ。
ソースコード
<?php
if ($dir = opendir("/hogehoge/hugahuga/sample/")) { //ディレクトリ開く
while (($file = readdir($dir)) !== false) { //ディレクトリから名前出してく
if ($file != '.htaccess') { //読み込んで欲しくないファイルはここではじく
echo "<a href='https://test.com/sample/$file/' target='_blank'>$file</a>\n<br />";
}
}
closedir($dir);
}
?>
リファレンス
opendir
https://www.php.net/manual/ja/function.opendir.php
readdir
https://www.php.net/manual/ja/function.readdir.php
closedir
関連記事
-
-
時間と数字のフォーマット
教わったのでメモ。 ・時間の整形 strtotime() 例) $ymd = ' ...
-
-
PHPからDBX Platformを利用してDropbox内のファイルを削除する方法
以前にPHPからDropboxのファイル一覧のデータ(ファイル名や更新日時等)を ...
-
-
PHPで「Unable to allocate~」とエラー
PHPで「Unable to allocate memory for pool」 ...
-
-
PHPにて「みんなの自動翻訳」のAPIで指定したテキストの言語判定する方法
迷惑メール対策等でメール本文が日本語のもののみ受信したい場合がある。ただ、本文内 ...
-
-
PHPでプロキシ経由で他サーバーに接続する方法(file_get_contents / curlの2パターン)
PHPでfile_get_contentsやcurlで他サーバに接続する際に自サ ...