Page 1 of 1

Sort by read dir

Posted: Mon Feb 08, 2010 3:16 pm
by simkrist
Hi

I'm trying to make a xml file using read dir and mark it with a number. So far, so good.. but How do I sort it by name, its seems to sort it by created date.

Can someone please help me

Regards
Stoijan

Code: Select all

<?php header('Content-Type: text/xml');
 
ini_set('allow_url_fopen', 'On');
ini_set('allow_url_include', 'On');
 
$path = "/";
$dirname=$_GET["id"];
$counter=0;
$fildir = "$dirname/";
$thumbdir = "$dirname/tumbs/";
//$dirname = ".";
 
if ($dirname == ""){
   echo "<?xml version='1.0' encoding='iso-8859-1' standalone='yes'?>";
   echo "<order baseuri='".$path."/' imagecount='".$counter."' orderno='".$dirname."' videovisning='http://www.nn.nn/streaming/".$dirname."/videovisning.html'>";
   echo "<status>";
   echo "<code>Failed</code>";
   echo "<active>false</active>";
   echo "<refnr>".$dirname."</refnr>";
   echo "<message>Du tastet ikke inn et referansenummer</message>";
   echo "</status>";
   echo "</order>";
} elseif (! is_dir($dirname)) {
   echo "<?xml version='1.0' encoding='iso-8859-1' standalone='yes'?>";
   echo "<order baseuri='".$path."/' imagecount='".$counter."' orderno='".$dirname."' videovisning='http://www.nn.nn/streaming/".$dirname."/videovisning.html'>";
   echo "<status>";
   echo "<code>Failed</code>";
   echo "<active>false</active>";
   echo "<refnr>".$dirname."</refnr>";
   echo "<message>Referansenummeret du tastet inn er ukjent</message>";
   echo "</status>";
   echo "</order>";
}
else {
  $dh = opendir($dirname) or die("Ukjent id: ".$dirname);
 
  while (!(($file = readdir($dh)) === false ) ) {
   if (! is_dir("$dirname/$file")) {
   $counter=$counter+1;
   }
  }
 
 
  echo "<?xml version='1.0' encoding='iso-8859-1' standalone='yes'?>";
  echo "<order baseuri='".$path."/' imagecount='".$counter."' orderno='".$dirname."' videovisning='http://www.nn.nn/streaming/".$dirname."/videovisning.html'>";
  echo "<status>";
  echo "<code>OK</code>";
  echo "<active>true</active>";
  echo "<refnr>".$dirname."</refnr>";
  echo "<message />";
  echo "</status>";
  echo "<images>";
 
  $counter=0;
 
  closedir($dh);
 
  $dh = opendir($dirname) or die("Ukjent id: ".$dirname);
 
  while (!(($file = readdir($dh)) === false ) ) {
   if (! is_dir("$dirname/$file")) {
   $sort=$counter+1;
   $thumbsize = getimagesize($thumbdir.$file);
   $storsize = getimagesize($fildir.$file);
   $thumbfilesize = filesize($thumbdir.$file);
   $originalfilesize = filesize($fildir.$file);
 
   $string = "$file";
   $bildenavn = basename($string,".jpg");
   echo "<image id='10".$counter."' sortorder='".$sort."' title='".$bildenavn."'>";
   echo "<format dpi='150' mime='$thumbsize[mime]' filesizeKB='$thumbfilesize' $thumbsize[3] name='thumbnail' relurl='".$dirname."/tumbs/".$file."'/>";
   echo "<format dpi='150' mime='$storsize[mime]' filesizeKB='$originalfilesize' $storsize[3] name='original' relurl='".$dirname."/".$file."'/>";
   echo "</image>";
   $counter=$counter+1;
   }
  }
  echo "</images>";
  echo "</order>";
  closedir($dh);
}
 
?>
 

Re: Sort by read dir

Posted: Mon Feb 08, 2010 3:22 pm
by Christopher
You can sort the array, or take a look at glob().

Re: Sort by read dir

Posted: Tue Feb 09, 2010 3:09 am
by simkrist
Arghhh... can't make it work. Still gets it sorted by date.