#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Sort images by date


    Hi!

    I have an image slideshow with next and previus buttons, but it shows first image in alphabetic sequence. I need it shows the last uploaded image, that what is uploaded in image directory, like sort by date. Sorry for my bad English.

    Here is the script
    [php]<?php
    $imageDirectory = "images";
    $interval = 5;
    ?>


    <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>
    [php]

    Thanks!
  2. #2
  3. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,688
    Rep Power
    171
    I highly doubt if anyone's gonna respond to your question like this. Use PHP an CODE tags properly so helpers can read your code.Read this.
    Good luck

IMN logo majestic logo threadwatch logo seochat tools logo