phpでファイルの拡張子を取得するにはどうすればよいですか?
ファイルの拡張子を格納するにはPHPのpathinfo()関数かexplode()関数を使用できます。
pathinfo() 関数を使用する
$file = 'example.txt';
$ext = pathinfo($file, PATHINFO_EXTENSION);
echo $ext; // 输出:txt
explode() 関数を使用する。
$file = 'example.txt';
$ext = explode('.', $file);
$ext = end($ext);
echo $ext; // 输出:txt
どちらの方法でもファイルの拡張子を取得することができます。