Hey all,
So I'm trying to create a button that will open a random .php file from a given directory. I'm relatively new to .php (like, I've been diving in for the past 3 weeks), so I don't understand a lot of the nitty-gritty stuff. But I've been able to tweak some code (originally for displaying random images) and get it to almost do what I want:

PHP Code:
$types = array(
"PHP" => "php");
$file_list = array();
$image_path realpath(trim($image_path) != "" $image_path ".") . "/";
  if (
$image_path !== false && is_dir($image_path) && $handle = @opendir($image_path)) {
    while ((
$file readdir($handle)) !== false) {
      if (
is_file($image_path $file)) {
$file_extension strtoupper(substr(strrchr($file"."), 1));
        if (isset(
$types[$file_extension])) {
$file_list[] = array(
"filename" => $image_path $file,
"mimetype" => $types[$file_extension]); } } } }
  if (
sizeof($file_list) > 0) {
readfile($file_list[0]["filename"]); }
  else { die(
"No files found."); }
I'm getting a random file, but it's displaying the whole page instead of a link. I know i need to use echo and <a href> in there at the end, but I don't know how. I tried about a dozen different variations on $file_list, $file, "filename", etc., but nothing worked.

I am grateful for ideas. Thanks!!