PHP file management. You can click to sort by time, size, and name.
Jquery is not used in this example.
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: cocould not change to this directory! ");
- $ Dirobject = dir ($ subdir );
- Echo"
- $ I = 0;
- $ Allfilesize + = filesize ($ file );
- While ($ file = $ dirobject-> read ()){
-
- If ($ file = "." | $ file = ".."){
- Continue;
- }
- $ I = $ I + 1;
- Echo"
- $ Filenum ++;
- }
- Echo"
File Name |
File Size |
Creation Time |
";
". $ I ."";- Echo $ file ."
|
". Number_format (filesize ($ file)/1024), 2, '.',''). "KB |
". Date (" Y-m-d H: I: s ", filemtime ($ file ))." |
";
";
- Return;
- }
- ?>
-
- <Script src = "table_sort.js"> </script>
JavaScript Code
- /**
- * Table sorting
- * Anthor liueh
- */
- Function JM_PowerList (colNum)
- {
- HeadEventObject = event. srcElement; // gets the object that raises the event
- While (headEventObject. tagName! = "TR") // If the row is not tr, find the corresponding row from the td bubble below
- {
- HeadEventObject = headEventObject. parentElement;
- }
-
- For (I = 0; I {
- If (headEventObject. children [I]! = Event. srcElement) // locate 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 to be a able. 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 the row is not ignored, 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 row in the array
- TdinnerHTML [i0] = trObject [I]. children [colNum]. innerHTML; // put the content of td in the row to be sorted in the array
- TdNumber [i0] = I; // row number
- I0 ++; // Add one, which is used in the next cycle
- }
- }
- SourceHTML = clearStart. children [0]. outerHTML; // obtain the html code of all tr in the table.
-
- // Sort all the strings in td. It is not a 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'; // store the sorted td content in the showshow string.
- Numshow = numshow + tdNumber [I] + '|'; // The sorted row number also exists in numshow.
- }
-
- SourceHTML_head = sourceHTML. split (""); // FromTruncation. I tried it. The front string is empty.
-
- Numshow = numshow. split ("| ");
- Var trRebuildHTML = '';
- If (event. srcElement. className = 'listheadclicked ')
- {// The column that has been clicked is reversed
- For (I = 0; I {
- TrRebuildHTML = trRebuildHTML + trObject [numshow [tableRows-1-i]. outerHTML; // retrieve the sorted tr content to connect
-
- }
- Event. srcElement. className = 'listheadclicked0 ';
- }
- Else
- {// The default value is "Forward". Click "forward ".
- For (I = 0; I {
- TrRebuildHTML = trRebuildHTML + trObject [numshow [I]. outerHTML;
- }
- Event. srcElement. className = 'listheadclicked ';
- }
- // Obtain the sorted tr set result string
- Var DataRebuildTable = '';
- // Link the old table header with the new elements sorted by tr (modified)
- DataRebuildTable ="
-
- "
"+ TrObject [0]. outerHTML + trRebuildHTML +"
"+
";
- ClearStart. outerHTML = DataRebuildTable; // The table is rewritten with a new string.
-
- }
Address: http://www.freejs.net/article_jquerywenzi_147.html