Advertisement
tjromano

index

Nov 10th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?PHP
  2.  
  3. $directory="/web/magicmurals/prod/images/upload/";
  4. $sortOrder="newestFirst";
  5.  
  6.    $results = array();
  7.    $handler = opendir($directory);
  8.  
  9. echo "<h3>Custom Upload files</h3>";
  10.  
  11. while ($file = readdir($handler)) {
  12.        if ($file != '.' && $file != '..' && $file != "robots.txt" && $file != ".htaccess" && $file !='index.php'){
  13.            $currentModified = filectime($directory."/".$file);
  14.            $file_names[] = $file;
  15.            $file_dates[] = $currentModified;
  16.        }  
  17.    }
  18.        closedir($handler);
  19.  
  20.    //Sort the date array by preferred order
  21.    if ($sortOrder == "newestFirst"){
  22.        arsort($file_dates);
  23.    }else{
  24.        asort($file_dates);
  25.    }
  26.  
  27.    //Match file_names array to file_dates array
  28.    $file_names_Array = array_keys($file_dates);
  29.    foreach ($file_names_Array as $idx => $name) $name=$file_names[$name];
  30.    $file_dates = array_merge($file_dates);
  31.  
  32.    $i = 0;
  33.  
  34.    //Loop through dates array and then echo the list
  35.    foreach ($file_dates as $$file_dates){
  36.        $date = $file_dates;
  37.        $j = $file_names_Array[$i];
  38.        $file = $file_names[$j];
  39.        $i++;
  40.  
  41.        echo  "<a href='$file' target='_blank'>$file</a><br>";      
  42.    }
  43.  
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement