ディレクトリに設置してあるフォルダを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
関連記事
-
-
UTF-16にエンコードされている文字列をUTF-8へデコード
エンコードされている文字列であまり見かけない感じのものがあった。UTF-8やSh ...
-
-
PHPとajaxでチャットの作成
■ソース ・index.php <? error_reporting(E_ ...
-
-
CodeIgniter4.4.4のインストールからHello Worldページ表示まで行う方法
以前CodeIgniter3を勉強したことがあったが新バージョンの4系がリリース ...
-
-
FPDIで「This PDF document probably uses~~」エラーの対処方法
FPIDであるPDFを読み込ませようとすると「This PDF document ...
-
-
opauthのTwitterでログインできない際の対応方法
opauthを使ったソーシャルログインのシステムにてTwitterでログインでき ...