Flash File Uploader v3.3

For those of you using the [d]online Flash File Uploader, a recent blog comment requested that the output directory change the sort method to be alphabetical. The changes from version 3.2 are quite simple, particularly if you have a PHP guru like Mike working for you.

Simply change lines 127-163 in index.php from:

if(file_exists("$dir/")){       
	if ($handle = opendir("$dir/")){       
		$count = 0;
		while (false !== ($file = readdir($handle))){
			if($file != "." && $file != ".." && $file != ".s"){
				$count++;
				if(!file_exists(getcwd()."/$dir/.s/$file") && array_key_exists(strtolower(substr($file,-3)),$imgtypes))
				{
					$srcf = getcwd()."/$dir/$file";
					$dstf = getcwd()."/$dir/.s/$file";
					$type = $imgtypes[strtolower(substr($file,-3))];
					mcSaveImages(120,90,$srcf,$dstf,15,$type);
				}
				echo "<tr bgcolor='".($count%2?"#FFFFFF":"#EFEFEF")."'>
					<td valign='top'>$count.</td>
					<td valign='top'>$file</td>
					<td valign='top'>".date("m/d/Y h:i:s A",filectime(getcwd()."/$dir/$file"))."</td>
					<td valign='top'>".niceSize(filesize(getcwd()."/$dir/$file"))."</td>";
				if($showthumbs){
					if(array_key_exists(strtolower(substr($file,-3)),$imgtypes))
					{ echo "<td><br />";
					} else { echo "<td align='left'>"; }
					$details = $id3->analyze(getcwd()."/$dir/$file");
					echo "<font size='-3'>";
					if(@array_key_exists("video",$details)) { echo "<b>IMAGE DETAILS:</b><hr width='200' align='left' style='border:1px solid #000;'></hr><ul>"; foreach($details['video'] as $k=>$v) { echo "<b>$k:</b> $v<br />"; } if(@$details['playtime_string']) { echo "<b>Playtime:</b> {$details['playtime_string']}<br />"; }echo "</ul>"; }
					if(@array_key_exists("audio",$details)) { echo "<b>AUDIO DETAILS:</b><hr width='200' align='left' style='border:1px solid #000;'></hr><ul>"; foreach($details['audio'] as $k=>$v) { echo "<b>$k:</b> $v<br />"; } echo "</ul>"; }
					echo "</td>";
				} else  { 
					echo "<td>&nbsp;</td>"; 
				}
				echo "</tr>";
			}
		}
		closedir($handle);
	}
}

to the following:

$assets = array(); 
if(file_exists("$dir/")){
	if ($handle = opendir("$dir/")){
		while (false !== ($file = readdir($handle))){
			if($file != "." && $file != ".." && $file != ".s") $assets[] = $file;                           
		}
		closedir($handle);
 
		natcasesort($assets); $n = 0;
		foreach($assets as $file){       
			if(!file_exists(getcwd()."/$dir/.s/$file") && array_key_exists(strtolower(substr($file,-3)),$imgtypes)){       $srcf = getcwd()."/$dir/$file";
					$dstf = getcwd()."/$dir/.s/$file";
					$type = $imgtypes[strtolower(substr($file,-3))];
					mcSaveImages(120,90,$srcf,$dstf,15,$type);
			}
			$n++;
			echo "<tr bgcolor='".($n%2?"#FFFFFF":"#EFEFEF")."'>
					<td valign='top'>$n.</td>
					<td valign='top'>$file</td>
					<td valign='top'>".date("m/d/Y h:i:s A",filectime(getcwd()."/$dir/$file"))."</td>
					<td valign='top'>".niceSize(filesize(getcwd()."/$dir/$file"))."</td>";
			if($showthumbs){
					if(array_key_exists(strtolower(substr($file,-3)),$imgtypes)){ 
						echo "<td><br />";
					} else { 
						echo "<td align='left'>"; 
					}
					$details = $id3->analyze(getcwd()."/$dir/$file");
					echo "<font size='-3'>";
					if(@array_key_exists("video",$details)) { echo "<b>IMAGE DETAILS:</b><hr width='200' align='left' style='border:1px solid #000;'></hr><ul>"; foreach($details['video'] as $k=>$v) { echo "<b>$k:</b> $v<br />"; } if(@$details['playtime_string']) { echo "<b>Playtime:</b> {$details['playtime_string']}<br />"; }echo "</ul>"; }
					if(@array_key_exists("audio",$details)) { echo "<b>AUDIO DETAILS:</b><hr width='200' align='left' style='border:1px solid #000;'></hr><ul>"; foreach($details['audio'] as $k=>$v) { echo "<b>$k:</b> $v<br />"; } echo "</ul>"; }
					echo "</td>";
			} else  { 
				echo "<td>&nbsp;</td>"; 
			}
			echo "</tr>";
		}
	}               
}

For more information, look into: http://php.net/manual/en/function.natcasesort.php

Leave a Reply

Your email address will not be published. Required fields are marked *