logo
Tags down

shadow

Sort array by time only on image echos


By : JDWalker
Date : May 03 2020, 09:29 AM

I need to sort these echo results by using time, and I can't seen to find a way to read when was the image placed on the folder (to sort them by the specific time).

<?php
  $all_files = glob(DIR_PATH."*.*");
  for ($i=0; $i<count($all_files); $i++)
    {
      $image_name = $all_files[$i];
      $supported_format = array('gif','jpg','jpeg','png');
      $ext = strtolower(pathinfo($image_name, PATHINFO_EXTENSION));
      if (in_array($ext, $supported_format))
          {
            echo '<div class="col" ><img src="/led/images/autoplay/'.str_replace(DIR_PATH,'',$image_name) .' " /><div align="center"><br /><a href="javascript:deleteImg(\''.$image_name.'\')" class="myButton">Delete</a></div><br /></div>';

          } else {
              continue;
          }  
    }

?>
Answer :

you can using usort() and filetime() function:

$files = glob(DIR_PATH."*.*");
usort( $files, function( $a, $b ) {
    return filemtime($a) - filemtime($b);
} );

foreach ($files as $file) {
    $image_name = $file;
    $supported_format = array('gif','jpg','jpeg','png');
    $ext = strtolower(pathinfo($image_name, PATHINFO_EXTENSION));
    if (in_array($ext, $supported_format))
    {
        echo '<div class="col" ><img src="/led/images/autoplay/'.str_replace(DIR_PATH,'',$image_name) .' " /><div align="center"><br /><a href="javascript:deleteImg(\''.$image_name.'\')" class="myButton">Delete</a></div><br /></div>';

    } else {
        continue;
    }
}


Share : facebook icon twitter icon
Related Posts Related Posts :
  • clear array after form submit
  • pass url variable to javascript
  • access data using api
  • div position fixed css
  • add horizontal line between two div
  • disable toggle button css
  • css fixed line height
  • background image not working
  • table cell border
  • text line break css
  • overlay div on div
  • text direction rtl css
  • javascript convert string to an object
  • bind inner div click to outer div
  • jquery ajax oncomplete
  • how to use promise in for loop
  • jquery get element using variable
  • javascript send textbox value
  • pass div class content to another class or id
  • css new line after element
  • css calc not working properly
  • link disabled jquery
  • sql join table to subquery
  • MS Access SQL Issue with OR AND Operators
  • set textarea value using php
  • php merge two arrays into one
  • php form with google captcha
  • update current row in php
  • php date format mysql
  • mysql pdo select query
  • php function return an array
  • PHP mysqldump database to sql file
  • display image query
  • php create array using foreach loop
  • associative array php
  • group_concat in mysql laravel
  • php array_push empty
  • mysql on update cascade not working
  • pdo insert prepared statement
  • mysql insert ignore vs on duplicate key
  • mysql insert into existing row
  • mysql multi insert query
  • mysql group by show all rows
  • php change profile image
  • combine multiple arrays into one array php
  • how to sum values in an array
  • how to get sum of the total time
  • How to Create Facebook live stream without notification using API ?
  • on button click make div visible
  • css affect another element on hover
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org