Skip to content

Instantly share code, notes, and snippets.

@prawee
Last active June 11, 2020 06:42
Show Gist options
  • Save prawee/da1c1bf4129f92c39b9a3be2986a8200 to your computer and use it in GitHub Desktop.
Save prawee/da1c1bf4129f92c39b9a3be2986a8200 to your computer and use it in GitHub Desktop.
using php read properties of folder or file
<?php
/**
* @link http://www.prawee.com
* 11/06/2020 11:03 AM
* @copyright Copyright (c) 2020 served
* @author Prawee Wongsa <prawee.wongsa@allianz.com>
* @license BSD-3-Clause
*/
date_default_timezone_set('Asia/Bangkok');
$path = 'docs';
$files = scandir($path, SCANDIR_SORT_DESCENDING);
$ignored = array('.', '..', '.svn', '.htaccess');
$results = [];
foreach($files as $file) {
if (in_array($file, $ignored)) continue;
$pathOfFile = $path.DIRECTORY_SEPARATOR.$file;
if (file_exists($pathOfFile)) {
$time = date ("Y-m-d H:i:s", filemtime($pathOfFile));
$results[$time] = $file;
}
}
krsort($results);
echo '<pre>'.print_r($results, true).'</pre>';
/*
Array
(
[2020-06-11 13:32:14] => test2.xlsx
[2020-06-11 13:24:13] => exp1.XLSX
)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment