Jump to content

using filemtime to seperate files by date


hellonoko

Recommended Posts

My below code displays a directory contents listing.

 

I am trying to make it separate the files into blocks based on the day value of the modified date of the file.

 

While looping through the files. If the date of the last file displayed is different than the current file the script inserts a second <br>

 

For some reason though I can not get it to put the double breaks in the correct place.

 

http://www.sharingizcaring.com/REPOSITORY/

 

<?php

include '../menu.php';

echo '<br>';

include '../count2.php';

   	$arr = array();

   	foreach (glob("*.*") as $filename) 
   	{
      	$arr[$filename] = filemtime($filename);
    	//echo $filename . " was last modified on " . date('M d Y, h:i:m', filemtime($filename)) . "<br>";    
   	}

   ///
   
   //asort($arr);
   //echo "<br>";

//foreach($arr as $key => $value) 
   	//{
    //	echo "$key was last modified on " . date('M d Y, h:i:m', $value) . "<br>";
   	//}

///

   	arsort($arr);
   	echo "<br>";

$olddate = 0;

   	foreach($arr as $key => $value) 
{
     
	if ( $key !== "filelist3.php" && $key !== "index.php" )
	{

		echo $date = date("d", filemtime($key));

		if ( $date !== $olddate )
		{
			echo "<br><br>";				
		}
		else
		{
			echo "<br>";
		}



		print "<object type=\"application/x-shockwave-flash\" data=\"http://www.sharingizcaring.com/button/musicplayer.swf?&song_url=http://www.sharingizcaring.com/REPOSITORY/$key&b_colors=,,ff0000,&\" width=\"17\" height=\"17\"";
         	print "<param name=\"movie\" value=\"http://www.sharingizcaring.com/button/musicplayer.swf?&song_url=http://www.sharingizcaring.com/REPOSITORY/$key&b_colors=,,ff0000,&\"</object>";

         	//print "<img src=\"noflash.gif\" width=\"17\" height=\"17\" alt=\"\" />";
         	print "<span class=small_font><a href=\"http://www.sharingizcaring.com/REPOSITORY/$key\" class=".color()."> $key</a></span>";



		$olddate = $date;	

		//echo "<br>";



	}
   	} 

function color()
{

	$color =  rand( 1,7);

	if ($color == 1)
	{
		return "red";
	}
	if ($color == 2)
	{
		return "green";
	}
	if ($color == 3)
	{
		return "blue";
	}
	if ($color == 4)
	{
		return "yellow";
	}
	if ($color == 5)
	{
		return "babyblue";
	}
	if ($color == 6)
	{
		return "purple";
	}
	if ($color == 7)
	{
		return "grey";
	}
}
?>

</body>
</html>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.