2009/07/23

[PHP]ディレクトリ内のjpgをランダムに表示

// ディレクトリを指定。省略時は topというディレクトリ
function randjpg($tagdir = 'top')
{
  if ($dh = opendir($tagdir)) {
    $i = 0;
    while ($file = readdir($dh)) {
      if (preg_match ('/.jpg$/', $file)) {
        $pict[$i++] = $file;
      }
    }
    closedir($dh);
    $tag = $tagdir . '/' . $pict[rand(0, $i - 1)];

    print "<img src=\"{$tag}\" alt=\"\" />";
  } else {
    print "directory open error\n";
  }
}

今見ると適当すぎる...

0 件のコメント:

Ubuntu 24.04 Server で VitualBoxの Autostartを

 VirtualBoxのインストールをを aptでインストールしたが autostartでvmが起動しなかったのでChatGPTに聞きながらやっと起動できるようになったのでそのメモ。