php file management, you can click to sort by time, size, name
This example does not use jquery
Demo
PHP Code
-
$rootdir="./";
- $spacenum=0;
- $filenum=0;
- $allfilesize=0;
- echo "
File management freejs.net test
";
- echo "Reset";
- readLogDir($rootdir);
- echo "
";
- echo "Total files count: $filenum.
" ;
- echo "Total disk space used: $allfilesize
";
- $freespace=diskfreespace("/");
- echo "residue disk space: $freespace
";
-
- function readLogDir($subdir){
- global $rootdir,$spacenum,$filenum,$allfilesize;
-
- @chdir($subdir) or die ("error:could not change to this directory !");
- $dirobject=dir($subdir);
- echo "
File name |
File size |
Creation time |
";
文件名 |
文件大小 |
创建时间 |
"; - $i=0;
- while ($file=$dirobject->read()){
-
- if($file=="." || $file==".."){
- continue;
- }
- $i=$i+1;
- echo "
".$i.""; - echo $file."
|
". number_format((filesize($file)/1024),2,'.','')."KB |
". date("Y-m-d H:i:s", filemtime($file)). " |
";
- $allfilesize+=filesize($file);
- $filenum++;
- }
- echo "
$i=0; while ($file=$dirobject->read()){ if($file=="." || $file==".."){ continue; } $i=$i+1; echo "
".$i.""; echo $file." |
". number_format((filesize($file)/1024),2,'.','')."KB |
". date("Y-m-d H:i:s", filemtime($file )). " |
"; $allfilesize+=filesize($file); $filenum++; } echo "
";
- return;
- }
- ?>
-
-
JavaScript Code - /**
- * table sorting
- * anthor liueh
- */
- function JM_PowerList(colNum)
- {
- headEventObject=event.srcElement;//Get the object that triggered the event
- while(headEventObject.tagName!=" TR") //If it is not the tr line, then bubble up from the td below to find the corresponding line
- {
- headEventObject=headEventObject.parentElement;
- }
-
- for (i=0; i{
- if (headEventObject.children[i]!=event.srcElement)//Find the td cell where the event occurred
- {
- headEventObject.children [i].className='listTableHead';//Set the className attribute of the clicked column to listTableHead
- }
- }
-
- var tableRows=0;
- trObject=clearStart.children[ 0].children; //Get the row object in the table. It turns out that this is called DataTable. Maybe you wrote it wrong??
- for (i=0;i{
- Object=clearStart.children[0].children[i];//Get the object of each row
- tableRows=(trObject[i].id=='ignore')?tableRows:tableRows+1;//If not Ignore rows, then add one to the number of rows
- }
-
- var trinnerHTML=new Array(tableRows);
- var tdinnerHTML=new Array(tableRows);
- var tdNumber=new Array(tableRows)
- var i0=0
- var i1=0
- for (i=0;i{
- if (trObject[i].id!='ignore ')
- {
- trinnerHTML[i0]=trObject[i].innerHTML;//Put the rows in the array
- tdinnerHTML[i0]=trObject[i].children[colNum].innerHTML;/ /Put the contents of td in the row to be sorted into the array
- tdNumber[i0]=i; //Row number
- i0++; //Add one, use
- }
- } sourceHTML=clearStart.children[0].outerHTML;//Get the html code of all tr in the table
-
- //Sort the strings in all td, is it considered bubble sort???
- for (bi=0;bi{ {
- for (i=0;i{
- if(tdinnerHTML[i]>tdinnerHTML[i+1])
- {
- t_s=tdNumber[i+1];
- t_b=tdNumber[i];
- tdNumber[i+1]=t_b;
- tdNumber[i]=t_s;
- temp_small=tdinnerHTML[i+1];
- temp_big=tdinnerHTML[i];
- tdinnerHTML[i+1]=temp_big;
- tdinnerHTML[i]=temp_small;
- }
- }
- }
-
-
-
- var showshow='';
- var numshow='';
- for (i=0;i{
- showshow=showshow+tdinnerHTML[i]+'n';//把排序好的td的内容存在showshow字串里
- numshow=numshow+tdNumber[i]+'|'; //把排序好的相应的行号也存在numshow中
- }
-
- sourceHTML_head=sourceHTML.split("");//从
截断,我试了,前头串为空
-
- numshow=numshow.split("|");
- var trRebuildHTML='';
- if (event.srcElement.className=='listHeadClicked')
- {//已点击的列, 则逆排
- for (i=0;i{
- trRebuildHTML=trRebuildHTML+trObject[numshow[tableRows-1-i]].outerHTML;//取出排序好的tr的内容连接起来
-
- }
- event.srcElement.className='listHeadClicked0';
- }
- else
- {//默认顺排,新点击顺排
- for (i=0;i{
- trRebuildHTML=trRebuildHTML+trObject[numshow[i]].outerHTML;
- }
- event.srcElement.className='listHeadClicked';
- }
- //取得排序后的tr集合结果字符串
- var DataRebuildTable='';
- //把旧的表格头和新的tr排序好的元素连接起来, (修改了一下)
- DataRebuildTable = "
" + trObject[0].outerHTML + trRebuildHTML + "" + -
- "
for (i=0;i{ if(tdinnerHTML[i]>tdinnerHTML[ i+1]) { t_s=tdNumber[i+1]; t_b=tdNumber[i]; tdNumber[i+1]=t_b; tdNumber[i] =t_s; temp_small=tdinnerHTML[i+1]; temp_big=tdinnerHTML[i]; tdinnerHTML[i+1]=temp_big; tdinnerHTML[i]=temp_small; } } } var showshow=''; var numshow=''; for (i=0;i{ showshow=showshow+tdinnerHTML[i]+'n';//Store the sorted td content in the showshow string numshow=numshow+tdNumber[i]+'|' ; //The corresponding sorted line numbers are also stored in numshow } sourceHTML_head=sourceHTML.split("");//Truncated from
, I tried, The front string is empty numshow=numshow.split("|"); var trRebuildHTML=''; if (event.srcElement.className=='listHeadClicked') { //The clicked column will be sorted in reverse order for (i=0;i{ trRebuildHTML=trRebuildHTML+trObject[numshow[tableRows-1-i]].outerHTML; //Take out the sorted tr contents and connect them } event.srcElement.className='listHeadClicked0'; } else {//Default order, new Click to sort for (i=0;i{ trRebuildHTML=trRebuildHTML+trObject[numshow[i]].outerHTML; } event.srcElement. className='listHeadClicked'; } //Get the sorted tr collection result string var DataRebuildTable=''; //Sort the old table header and the new tr The elements are connected, (modified) DataRebuildTable = "" + trObject[0].outerHTML + trRebuildHTML + "" + "
"; - clearStart.outerHTML=DataRebuildTable;//Rewrite the table with a new string
-
- }
Original address: http://www.freejs.net/article_jquerywenzi_147 .html
http://www.bkjia.com/PHPjc/769113.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/769113.htmlTechArticlephp file management, you can click to sort by time, size, name. This example does not use jquery. Demo PHP Code $rootdir ="./"; $spacenum=0; $filenum=0; $allfilesize=0; echo "File management...