<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>顯示文件夾內文件</title>
</head>
<body>
<?php
$sort_file=array();
$filefj=array();
define('FILEPATH','../filehandle/uploadfile/');
$sortlist=trim($_GET["sort"]);
$dir=opendir(FILEPATH);
echo'文件上傳位置:'.FILEPATH.'<br/>';
echo'文件列表:'.'<ul>';
if($sortlist == 'filetype'){
while (($file=readdir($dir))!== false) {
if ($file != "." && $file != "..") {
$file=basename($file);
$sort_file[]=$file;
}
}
foreach ($sort_file as $key=>$var) {
$filefj[]=explode('.',$var);
}
usort($filefj,'compare');
foreach ($filefj as $key=>$val){
$combinationfile=implode('.',$val);
echo '<li>'. $combinationfile.' </li>';
}
}else{
while (($file=readdir($dir))!== false) {
if ($file != "." && $file != "..") {
$file=basename($file);
echo '<li>'.$file.$file_size.' </li>';
}
}
}
echo '</ul>';
closedir($dir);
echo'</br>';
echo'<a href="index.php?sort=filetype">按文件類型排序</a> <a href="index.php">按正常文件排序</a> <a href="upfile.html">繼續上傳文件</a>';
function compare($x,$y){
if($x[1]==$y[1])
return 0;
else if ($x[1]<$y[1])
return -1;
else return 1;
}
?>
</body>
</html>
文件效果就不說了,自己試一一就知道了.