ディレクトリに設置してあるフォルダを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
関連記事
-
-
smart_resize_imageで縦横の比率関係なく、固定リサイズ
PHPで縦横どちらかが指定の長さを超えた場合、比率を保ったままリサイズで使ったs ...
-
-
FPDIで「This PDF document probably uses~~」エラーの対処方法
FPIDであるPDFを読み込ませようとすると「This PDF document ...
-
-
PodmanにComposerを導入し、パッケージをインストールする方法
先日Podmanで導入したapache-phpに各種PHPモジュールを追加したが ...
-
-
PHPとLINEを連携させて通知を送る方法(file_get_contents / curlの2パターン)
PHPとLINEを連携させ、LINEに何らかの通知メッセージを送信したい。以下に ...
-
-
PHPのsetcookieで「Cannot modify」エラーの対応方法
PHPでsetcookieを使うと「Warning: Cannot modify ...