Jump to content

Ordenar ficheiros por data


kenny
 Share

Go to solution Solved by HappyHippyHippo,

Recommended Posts

Boas estou com uma duvida eu tenho este ficheiro PHP para ir buscar uns ficheiros a um diretorio FTP.

Mas queria ordenar los por data como posso fazer lo?

 while($file = $contents[$count])
	{
$data[$count][year] = substr($file,35,2); // position 11 because of: "warserver1-09...
$data[$count][month] = substr($file,37,2);
$data[$count][day] = substr($file,39,2);
$data[$count][hour] = substr($file,41,2);
$data[$count][minute] = substr($file,43,2);
$data[$count][map] = substr($file,46,-4);
$data[$count][name] = $file;
$count++;
 }

 echo ("<table class='TableReports'>");
 echo ("<tr align='center'>");
 echo ("<td>Mapa</td>");
 echo ("<td>Data</td>");
 echo ("</tr>");

foreach($data as $field)
{
 $nome_demo = $field[name];
 echo ("<td>$field[map]</td>");
 echo ("<td>$field[day]/$field[month]/20$field[year] - $field[hour]:$field[minute]</td>");
 echo ("</tr>");
}
echo ("</table>");
Link to comment
Share on other sites


$files = [];
foreach($contents as $file) {
   $time = mktime(substr($file,41,2),  // hours
                  substr($file,43,2),  // minutes
                  0,                   // seconds
                  substr($file,37,2),  // month
                  substr($file,39,2),  // day
                  substr($file,35,2)); // year
   $files[$time] = array('name' => $file,
                         'map' => substr($file,46,-4));
}

echo ('<table class="TableReports">');
echo ('<tr>');
echo ('<td>Mapa</td>');
echo ('<td>Data</td>');
echo ('</tr>');

ksort($files);
foreach($files as $time => $file) {
 echo ('<tr>');
 echo ('<td>'.$file['map'].'</td>');
 echo ('<td>'.date('Y/m/d H:i:s', $time).'</td>');
 echo ('</tr>');
}
echo ('</table>');
Edited by HappyHippyHippo
  • Vote 1
IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.