Predmet:Re:Prikaz slucajno odabrane slike
<html>
<head>
<title>slika u tablu</title>
</head>
<body>
<?php
function get_rand_img($dir)
{
$arr = array();
$list = scandir($dir);
foreach($list as $path) // ovdje promijenjeno
{
if(!isset($img))
{
$img = '';
}
if(is_file($dir . '/' . $path)) // ovdje promijenjeno
{
$file = new SplFileInfo($path);
$ext = $file->getExtension();
//$ext = end(explode('.', $file));
if($ext == 'gif' || $ext == 'jpeg' || $ext == 'jpg' || $ext == 'png' || $ext == 'GIF' || $ext == 'JPEG' || $ext == 'JPG' || $ext == 'PNG')
{
array_push($arr, $file);
$img = $file;
}
}
}
if($img != '')
{
$img = array_rand($arr);
$img = $arr[$img];
}
$img = str_replace("'", "\'", $img);
$img = str_replace(" ", "%20", $img);
return $img;
}
?>
<table id="mainTable" width="578" height="351" border="1">
<tr>
<td><img src="<?php echo get_rand_img('images'); ?>" alt="" border=3 height=100 width=100></img></td>
<td>Some content</td>
<td>Some content</td>
</tr>
<tr>
<td>Some content</td>
<td>Some content</td>
<td>Some content</td>
</tr>
</table>
</body>
</html>
Podrska samo putem foruma, jer samo tako i ostali imaju koristi od toga.