Thanks for all your help and advice. I did struggle with the array part but got it worked out. Perhaps you could have a quick look at the script and let me know if it is stable enough. <?php function disfile($dir, $file, $num, $status) { /* $filelocation = $dir.$file; if(is_file($filelocation)) { $filesizefile = filesize($filelocation); if($filesizefile > 1048575) { $filesizefile = round(($filesizefile/1024)/1024, 1); $term = "Mb"; } elseif ($filesizefile < 1024) { $filesizefile = round(($filesizefile), 1); $term = "bytes"; } else { $filesizefile = round(($filesizefile/1024), 1); $term = "Kb"; } } */ $filelength = strlen($file); $disfile = substr($file, 0, ($filelength -3)); if($status == 'true') { $file_link .= "<INPUT TYPE=RADIO NAME=\"file_name\" VALUE=\"$dir$file\"> $disfile<br>"; }else{ $file_link .= "<li> <a href=\" $dir$file\" target=\"_blank\">" . $disfile . "</a></li>"; //<font size=1>($filesizefile $term)</font><br>"; } return $file_link; } function download($dir,$ms) { if (isset($_GET['download'])) { header("Content-Type: octet/stream"); header("Content-Disposition: attachment; filename=" . basename($_GET['download'])); //echo file_get_contents($_GET['download']); } else { if ($open = opendir($dir)) { $num = 0; $filenames = Array(); while (false !== ($file = readdir($open))) { if ($file != "." && $file != "..") { $filenames[]=$file; if (!is_dir($dir . $file)) { $num ++; } } } sort($filenames); $cout = count($filenames); for ($i = 0; $i < $cout; $i++) { $folder_files .= disfile($dir,$filenames[$i],$num,$ms); } } closedir($open); } return $folder_files; } ?>