Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-01-2012, 02:33 PM   PM User | #1
sandjuks112
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sandjuks112 is an unknown quantity at this point
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!
sandjuks112 is offline   Reply With Quote
Old 12-02-2012, 12:51 AM   PM User | #2
Junsee
New Coder

 
Join Date: Jun 2012
Posts: 42
Thanks: 4
Thanked 5 Times in 5 Posts
Junsee is an unknown quantity at this point
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 />';

Junsee is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:52 AM.


Advertisement
Log in to turn off these ads.