Jump to content

list by date...


mikem562

Recommended Posts

I have the following script which generated xml for me, I need a way though so the first <image> node is the newest image, and the last node is the oldest. so instead of it doing it via filename I would like to-do it by the date it was last touched. I plan on uploading images and upon running this script I want the most recently uploaded ones at the top...

 

<?php
$dir = '../galleries/music/';
$file_ext = "img.jpg";
      $play_list = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
      $play_list .= "<content>\n";
	$play_list .= "<gallery>\n";
      // Open directory, read contents and add to file_list if correct file_type
      if (is_dir($dir)) {
      	if ($dh = opendir($dir)) {
            	while (($file = readdir($dh)) !== false) {
                		if ($file != '.' && $file != '..') {
                   		$name_array = explode('_', $file);
                   			if ($name_array[1] == $file_ext) {
                			      $file_img = "$file";
					$file_tmb = str_replace("_img", "_tmb", "$file");
                  		 	$play_list .= "<image Thumb=\"$file_tmb\" Large=\"$file_img\"></image>\n";
                   			}
                			}
             		}
             	closedir($dh);
            	$play_list .= "</gallery>\n";
           		$play_list .= "</content>\n";
     		$wdir = ''.$dir.'images1.xml';
     		$f=fopen("$wdir","w") or die("Could not open and empty the file");
           		fwrite($f,$play_list) or die("Could not write to the file");
           		fclose($f) or die ("Could not close the resource");
    	      }
       }
?>

Link to comment
https://forums.phpfreaks.com/topic/170028-list-by-date/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.