Action: Random Image

just a blueprint, start from here..


{{randomimage}}


/actions/randomimage.php


<?php

if (!defined('IN_WACKO'))
{
    exit;
}

$path    UPLOAD_GLOBAL_DIR;
$names    = [];

    if (!
in_array($path, [UPLOAD_GLOBAL_DIR]))
    {
        return;
    }

    
$folder opendir($path);

    while (
$file readdir($folder))
    {
        
$names[] = $file;
    }

    
closedir($folder);

    
sort($names);

    if (
$names)
    {
        foreach (
$names as $name)
        {
            
$ext strtolower(substr($name, -4));

            if (
in_array($ext, ['.jpg''.gif''jpeg''.png']))
            {
                
$images[] = $name;
            }
        }

        
srand ((double) microtime() * 10000000);

        
$rand_keys    array_rand($images2);
        
$x_image    Ut::join_path($path$images[$rand_keys[0]]);
        
$dimensions    GetImageSize($x_image);

        if (isset(
$pic))
        {
            
header ("Location: $x_image");
        }
        else
        {
            echo 
'<img src="' $x_image '" ' $dimensions[3] . '>';
        }
    }

?>

To Do

  • add parameters to filter for size, dimension, user, file tag, ...
  • user file table
  • alt text, show image name
  • if used wacko files/perpage folder check acls
  • limit path