Hi!
I have an image slideshow, but it shows first image in alphabetic sequence. I need it shows the fist image, that what has last uploaded in image folder, like sort by date. Sorry for my bad English.
Here is the script
<?php
$imageDirectory = "images";
$interval = 5;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Slideshow</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var picn=0;
var picList = new Array;
var actImg = new Image();
<?php
if ($handle = @opendir($imageDirectory)) {
$i = 0;
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$path = $imageDirectory;
if(is_file($path.DIRECTORY_SEPARATOR.$file)) {
$info = $path_parts = pathinfo($file);
if ( (strtolower($info['extension']) == 'jpg')
|| (strtolower($info['extension']) == 'jpeg')) {
$file = addslashes($file);
echo "picList[$i] = '$path/$file';\r\n";
$i++;
}
}
}
}
}
?>
function setCountDown ()
{
actImg.src = picList[picn++];
document.getElementById("pic").src=actImg.src;
if (picn>=picList.length) picn=0;
setTimeout ( "setCountDown()", <?php echo ($interval*100000); ?> );
}
var imgNum = 0;
$("#0").fadeIn(300);
function prev () {
actImg.src = picList[picn--];
document.getElementById("pic").src=actImg.src;
imgNum = newImageNum;
}
function next () {
actImg.src = picList[picn++];
document.getElementById("pic").src=actImg.src;
imgNum = newImageNum;
}
</script>
</head>
<div class="gallery-controls">
<button onclick="prev()">Previous</a>
<button onclick="next()">Next</a>
</div>
<body onload="setCountDown();">
<div id="container">
<div id="header"><div id="header_left"></div>
<div id="header_main">SlideShow</div><div id="header_right"></div></div>
<div id="content">
<img src="<?php echo $path.'/'.$file; ?>" alt="pic" id="pic" border="1" />
</div>
<div id="footer"><a href="" target="_blank"></a></div>
</div>
</body>
</html>
Thanks!