Wednesday, 3 January 2018

How to Get Both Files and Directories:

To get both files and directories, the script is even simpler, simply take out the last if statement so your final code looks like:
//get ELEMENTS in uploads/
$path = "uploads";    
$d = dir($path);
    while (false !== ($entry = $d->read())) {
    $filepath = "{$path}/{$entry}";
    $latest_ctime = filectime($filepath);//like: 1402783996 that is timestamp so highest is latest.
    $latest_filename = $entry;
    $file_type = filetype($filepath);//get file type.
    $file_size = filesize($filepath);//get file size.
    echo "$latest_filename<br />Type: $file_type<br />Size: $file_size<hr />";
    }//end while going over files AND DIRECTORIES in uploads dir.

0 comments:

Post a Comment