ディレクトリに設置してあるフォルダを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
関連記事
-
-
DTIのVPSにCodeigniter3を導入する方法
DTIのVPSにPHPフレームワークのCodeigniter3系をインストールし ...
-
-
PHPでデータをファイルキャッシュさせる(Cache_Lite)
最近携わった案件でPHPでファイルキャッシュをしているシステムがあった。今までフ ...
-
-
PHPのHTTPクライアント用ライブラリ「Guzzle」の利用方法
以前に「Requests for PHP」を試したが、似たようなライブラリで「G ...
-
-
PHPでGoogle翻訳を手軽に扱えるライブラリ「google-translate-php」の利用方法
サイト内で一部テキストのGoogle翻訳を行いたい。ただ、Google Clou ...
-
-
CodeIgniter4&Bootstrap&jQueryで簡易版お問い合わせページの作成
CodeIgniter4.4.4&Bootstrap&jQuer ...