Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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,and then when I press next image it goes to previus uploaded image, 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
    Junsee
    Guest
    I use this

    PHP Code:
    foreach (glob("../FOLDER/*") as $path) { 
        
    $docs[$path] = filectime($path);
    arsort($docs); 

    foreach (
    $docs as $path => $timestamp) {
        print 
    '<a href="'$path .'">'basename($path) .'</a><br />';



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •