ディレクトリに設置してあるフォルダを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
関連記事
-
-
CodeIgniter3でログをファイルに出力する方法
Codeigniter3でエラーログの設定を行い特定のファイルに出力させ当該ログ ...
-
-
CodeIgniter4 & jQueryを用いて同一サイト内でajax通信する方法
CodeIgniter4.4.4 & jQueryを用いて同一サイト内で ...
-
-
PHPのsetcookieで「Cannot modify」エラーの対応方法
PHPでsetcookieを使うと「Warning: Cannot modify ...
-
-
CodeIgniter4 & reCAPTCHA でお問い合わせフォームを作成する方法
以前CodeIgniter4.4.4で簡易的なお問い合わせページを作成したが、今 ...
-
-
PHPで画像を上下反転させ保存する
やりたかった事は、下記の通り。 ・既にフォルダに保存されている画像を上下反転させ ...