PHP file management. You can click to sort by time, size, and name.

Source: Internet
Author: User

PHP file management. You can click to sort by time, size, and name.

Jquery is not used in this example.

Demo

PHP Code
  1. $ Rootdir = "./";
  2. $ Spacenum = 0;
  3. $ Filenum = 0;
  4. $ Allfilesize = 0;
  5. Echo "File Management freejs.net test ";
  6. Echo "reset ";
  7. ReadLogDir ($ rootdir );
  8. Echo "";
  9. Echo "Total files count: $ filenum.
    ";
  10. Echo "Total disk space used: $ allfilesize
    ";
  11. $ Freespace = diskfreespace ("/");
  12. Echo "residue disk space: $ freespace
    ";
  13. Function readLogDir ($ subdir ){
  14. Global $ rootdir, $ spacenum, $ filenum, $ allfilesize;
  15. @ Chdir ($ subdir) or die ("error: cocould not change to this directory! ");
  16. $ Dirobject = dir ($ subdir );
  17. Echo"
  18. $ I = 0;
  19. $ Allfilesize + = filesize ($ file );
  20. While ($ file = $ dirobject-> read ()){
  21. If ($ file = "." | $ file = ".."){
  22. Continue;
  23. }
  24. $ I = $ I + 1;
  25. Echo"
  26. $ Filenum ++;
  27. }
  28. Echo"
  29. "; ";
    File Name File Size Creation Time
    ". $ I ."";
  30. Echo $ file ."
  31. ". Number_format (filesize ($ file)/1024), 2, '.',''). "KB ". Date (" Y-m-d H: I: s ", filemtime ($ file ))."
    ";
  32. Return;
  33. }
  34. ?>
  35. <Script src = "table_sort.js"> </script>

    JavaScript Code
    1. /**
    2. * Table sorting
    3. * Anthor liueh
    4. */
    5. Function JM_PowerList (colNum)
    6. {
    7. HeadEventObject = event. srcElement; // gets the object that raises the event
    8. While (headEventObject. tagName! = "TR") // If the row is not tr, find the corresponding row from the td bubble below
    9. {
    10. HeadEventObject = headEventObject. parentElement;
    11. }
    12. For (I = 0; I {
    13. If (headEventObject. children [I]! = Event. srcElement) // locate the td cell where the event occurred
    14. {
    15. HeadEventObject. children [I]. className = 'listtablehead'; // set the className attribute of the clicked column to listTableHead.
    16. }
    17. }
    18. Var tableRows = 0;
    19. TrObject = clearStart. children [0]. children; // get the row object in the table. It turns out to be a able. Maybe you wrote it wrong ??
    20. For (I = 0; I {
    21. Object = clearStart. children [0]. children [I]; // get the Object of each row
    22. TableRows = (trObject [I]. id = 'ignore ')? TableRows: tableRows + 1; // If the row is not ignored, add one to the number of rows.
    23. }
    24. Var trinnerHTML = new Array (tableRows );
    25. Var tdinnerHTML = new Array (tableRows );
    26. Var tdNumber = new Array (tableRows)
    27. Var i0 = 0
    28. Var i1 = 0
    29. For (I = 0; I {
    30. If (trObject [I]. id! = 'Ignore ')
    31. {
    32. TrinnerHTML [i0] = trObject [I]. innerHTML; // put the row in the array
    33. TdinnerHTML [i0] = trObject [I]. children [colNum]. innerHTML; // put the content of td in the row to be sorted in the array
    34. TdNumber [i0] = I; // row number
    35. I0 ++; // Add one, which is used in the next cycle
    36. }
    37. }
    38. SourceHTML = clearStart. children [0]. outerHTML; // obtain the html code of all tr in the table.
    39. // Sort all the strings in td. It is not a bubble sort ???
    40. For (bi = 0; bi {
    41. For (I = 0; I {
    42. If (tdinnerHTML [I]> tdinnerHTML [I + 1])
    43. {
    44. T_s = tdNumber [I + 1];
    45. T_ B = tdNumber [I];
    46. TdNumber [I + 1] = t_ B;
    47. TdNumber [I] = t_s;
    48. Temp_small = tdinnerHTML [I + 1];
    49. Temp_big = tdinnerHTML [I];
    50. TdinnerHTML [I + 1] = temp_big;
    51. TdinnerHTML [I] = temp_small;
    52. }
    53. }
    54. }
    55. Var showshow = '';
    56. Var numshow = '';
    57. For (I = 0; I {
    58. Showshow = showshow + tdinnerHTML [I] + '\ n'; // store the sorted td content in the showshow string.
    59. Numshow = numshow + tdNumber [I] + '|'; // The sorted row number also exists in numshow.
    60. }
    61. SourceHTML_head = sourceHTML. split (""); // FromTruncation. I tried it. The front string is empty.
    62. Numshow = numshow. split ("| ");
    63. Var trRebuildHTML = '';
    64. If (event. srcElement. className = 'listheadclicked ')
    65. {// The column that has been clicked is reversed
    66. For (I = 0; I {
    67. TrRebuildHTML = trRebuildHTML + trObject [numshow [tableRows-1-i]. outerHTML; // retrieve the sorted tr content to connect
    68. }
    69. Event. srcElement. className = 'listheadclicked0 ';
    70. }
    71. Else
    72. {// The default value is "Forward". Click "forward ".
    73. For (I = 0; I {
    74. TrRebuildHTML = trRebuildHTML + trObject [numshow [I]. outerHTML;
    75. }
    76. Event. srcElement. className = 'listheadclicked ';
    77. }
    78. // Obtain the sorted tr set result string
    79. Var DataRebuildTable = '';
    80. // Link the old table header with the new elements sorted by tr (modified)
    81. DataRebuildTable ="
    82. "
    83. "+ TrObject [0]. outerHTML + trRebuildHTML +" "+
      ";
    84. ClearStart. outerHTML = DataRebuildTable; // The table is rewritten with a new string.
    85. }


      Address: http://www.freejs.net/article_jquerywenzi_147.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.