|
Posted by Rik on 09/29/19 11:52
Dave Kelly wrote:
> Jonathan N. Little wrote:
>> Toby Inkster wrote:
>>> Jonathan N. Little wrote:
>>>
>>>>> for filename in *.jpg *.gif *.png; ##list all images in directory
>>>>> do
>>>>> <img src=images/"${filename}" width="190">
>>>>> done
>>>> Sorry, no can do. HTML is only markup not scripting, to do what you
>>>> wish *requires* a script either server-side (best) PHP, Perl,
>>>> Python, ASP, ColdFusion, ... or client-side (not-so-good)
>>>> JavaScript.
>>>
>>> Client-side Javascript won't do -- it has no way of reading the
>>> contents of a directory on the server.
>> Yes, you would have to manually make the list, I focused on the
>> 'select image at random' part and overlooked the 'list all images in
>> directory' part.
>>
> I have found a couple of PHP apps that do the job. Keeping the list of
> images in the directory current was the problem. All I found required
> you to make a stable list. I have not figured how to update the list
> on the server.
>
> I know that EV1 runs PHP because I have the SMF code running. I just
> need to check and see what hooks to scheduling they have.
HTML: <img src="/path/to/dir/random.php" />
random.php:
<?php
$dh = opendir(dirname(__FILE__));
$images = array();
$img_extensions = array('jpeg','jpg','png','gif');
while (($file = readdir($dh))!==false){
if(is_file(dirname(__FILE__).'/'.$file)){
preg_match('/([^.]*)$/si',$file,$matches);
if(in_array(strtolower($matches[1]),$img_extensions)){
$images[] = $file;
}
}
}
closedir($dh);
$chosen ='./'.$images[rand(0,count($images)-1)];
$size = getimagesize($chosen);
header("Content-type: {$size['mime']}");
readfile($chosen);
?>
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|