とりあえずの備忘録

主にパソコンやインターネットに関するメモ

PHP 指定フォルダ内にあるJPG画像ファイルの数を調べる

/var/www/html/images内にあるJPG画像ファイルの数を調べる

<?php
//対象のディレクトリ
$target_dir = '/var/www/html/images';

//コマンドの実行結果を受け取る配列
$result = array();

$command = "find " . $target_dir . " -name '*.jpg' | wc -l";
exec($command, $result);

//出力
echo '画像ファイル数は、' . $result[0];
?>

「出力結果」

画像ファイル数は、68