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>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.