Files in the output directory
Functionoutputcurfiles ($allowedtypes, $thedir) {
First, we make sure that the directory exists.
Now, we use Scandir to scan the files in the directory.
$scanarray = Scandir ($thedir);
Then we start parsing the array.
Scandir () with "." and ".." Statistics file navigation list
So as a document, we should not list them.
for ($i = 0; $i <count ($scanarray); $i + +) {
if ($scanarray [$i]!= "." && $scanarray [$i]!= "...") {
Now, check to make sure that this is a file, not a directory.
if (Is_file ($thedir.) /". $scanarray [$i])) {
Now, because we will allow the client to edit this file,
We have to check whether it is readable and writable.
if (Is_writable ($thedir.) /". $scanarray [$i]) && is_readable ($thedir." /". $scanarray [$i])) {
Now, we check whether the file type exists in the allowed array of types.
$thepath =pathinfo ($thedir.) /". $scanarray [$i]);
if (In_array ($thepath [' extension '], $allowedtypes)) {
If the file complies with the rules, we can continue to output.
echo$scanarray[$i]. " <br/> ";
echo "Sorry, this directory does not exist."
$allowedtypes =array ("TXT", "html");
Outputcurfiles ($allowedtypes, "TestFolder");
///////////////////////////////////////////////////
Functionrecurdir ($thedir) {
Attempt to open the directory.
if ($adir = Opendir ($thedir)) {
while (false!== ($anitem = Readdir ($adir))) {
No statistics directory contains "." or ".." of the situation
if ($anitem!= "." && $anitem!= "...") {
At this point, if it's a directory, indent a little
And then go back to the recursive
if (Is_dir ($thedir.) /". $anitem)) {
? ><span style= "Font-weight:bold;" Mce_style= "Font-weight:bold;" ><?phpecho$anitem; ></span><?php
? ><div style= "margin-left:10px;" Mce_style= "margin-left:10px;" ><?php
Recurdir ($thedir. " /". $anitem);
}elseif (Is_file ($thedir.) /". $anitem)) {
The file is output at this time.
Thrownewexception ("Sorry, directory could not to be openend.");
echo "<br/>/////////////////////////////////////<br/><br/>";
//////////////////////////////////////////////////////////////////
echo "<br/>/////////////////////////////////////<br/><br/>";
Functionsortfilesbydate ($thedir) {
First, you need to make sure that the directory exists.
Next, we use Scandir to scan the files in this directory.
$scanarray = Scandir ($thedir);
Then start parsing the array
Scandir () with "." and ".." Statistics file navigation list
So as a document, we should not list them.
for ($i = 0; $i <count ($scanarray); $i + +) {
if ($scanarray [$i]!= "." && $scanarray [$i]!= "...") {
Now we check to make sure that this is a file and not a directory.
if (Is_file ($thedir.) /". $scanarray [$i])) {
What you need to do now is loop the data to an associative array.
$finalarray [$thedir.] /". $scanarray [$i]] =filemtime ($thedir." /". $scanarray [$i]);
Now that we've traversed the entire array, all we need to do is asort () it.
echo "Sorry, this directory does not exist."
We then point the function to the directory that we need to view.
$sortedarray = Sortfilesbydate ("TestFolder");
At this point, you can output as follows:
while ($element = each ($sortedarray)) {
echo "File:". $element [' key ']. "Is last modified:". Date ("F J, Y H:i:s", $element [' value ']). " <br/> ";