Page 1 of 1

Checking files

Posted: Mon Sep 08, 2003 2:06 am
by fernado1283
Hi,

I wondering anyone can help me with this please.
I had a drop down menu list which displays all the files in the folder.
Can anyone please tell me, how am I going to display only the lastest 10 files in the drop down menu. e.g I have 25 files in the folder, but I only want the lastest 10 files to be in the drop down menu for users to download.
Can anyone out there please help me. Thanks. :)

Code: Select all

<?php
if (isset($actionflag) && $actionflag == "download")
	{
		$passing = $selectXYZ;
	}
	htmlheader(); // prints html header


	$dir = "./"; // current directory


	// Print the directory name as a heading title 
	$filedir =  getcwd();  // get current dir
	$dirname = getHeader($filedir);
	print "<br>";
	print "<font size=+1 face="Times New Roman" color="Blue"><b> ";
	print "$dirname </b>";
	print "</font> ";
	print "<hr>";
	
	
	
	$file_array = array();
	$file_array = getFiles($dir); // displays all the files in the folder

	print "<form action="openFiles.php " name="selection" target="_blank">";
	print "<input type="hidden" name="actionflag" value="download">";
	print "<select name="selectXYZ">";

	
	foreach($file_array as $a_row)
	{
		// make sure it's not an include file or index file
		if (!strstr($a_row,".inc.php") && !strstr($a_row,"index.php") && !strstr($a_row, ".php"))
		{
			if (!is_dir($a_row)) // the file is not a directory
			{            	
				print "<option>$a_row</option>";
			}				
		}
	}

	print "</select> ";

	print "<input type="submit">";
	print "</form>";
?>
Regards...
Fernado

Posted: Mon Sep 08, 2003 8:27 am
by JAM
Change the

Code: Select all

foreach($file_array as $a_row)
to

Code: Select all

for ($i=0;$i=10;$i++)
// and change the $a_row to match etc etc
...then you have a loop that will only print 10 files. You should sort the files according to dates in your getFiles() function to have them in the order you want.

Posted: Mon Sep 08, 2003 7:57 pm
by fernado1283
Hi,
I've made the changes but it just wont display anything???
Can anyone help me please. Thanks...

Code: Select all

<?php
for ($i=0; $i=10; $i++)
	{
		$a_row = array();
		$a_row = $file_array(i); 
	
		// make sure it's not an include file or index file
		if (!strstr($a_row,".inc.php") && !strstr($a_row,"index.php") && !strstr($a_row, ".php"))
		{
			if (!is_dir($a_row)) // the file is not a directory
			{            	
				print "<option>$a_row</option>";
			}				
		}
	}
?>
Regards...
Fernado

Posted: Mon Sep 08, 2003 9:08 pm
by m3mn0n
You should sort the files according to dates in your getFiles() function to have them in the order you want.
How did that turn out?

Posted: Mon Sep 08, 2003 9:12 pm
by fernado1283
Hi,

What I mean initially was that after i change to this code, not a single file are being added into the drop down menu. The drop down menu become empty.
Do you know whats wrong with it.

Regards...
Fernado

Posted: Tue Sep 09, 2003 6:29 am
by pootergeist
as getFiles is a user function we have to guess at the array returned - you'll probably need to amend that function anyway to include the filemtime of each file.

either post the function getFiles() here or a var_dump or print_r of the found $file_array. As you are getting nowt I'd guess that the index holds the filename and the value is another array - that'd just be a guess though and may confuse further - so best to determine properly the function return.