PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
<?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>";
?>
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.
<?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>";
}
}
}
?>
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.
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.