PHP file Management, you can click by time, size, name sort

Source: Internet
Author: User
Tags array connect net php file php code sort split
PHP file Management, you can click by time, size, name sort

jquery is not used in this example

Demonstrate

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:could not on" 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. "; ";
    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 Sort
    3. * Anthor Liueh
    4. */
    5. function Jm_powerlist (colnum)
    6. {
    7. headeventobject=event.srcelement;//to get the object that raised the event
    8. while (headeventobject.tagname!= "tr")//is not a TR line, the following TD bubbles up to find the appropriate line
    9. {
    10. Headeventobject=headeventobject.parentelement;
    11. }
    12. for (i=0;i
    13. {
    14. if (headeventobject.children[i]!=event.srcelement)//Find the TD cell where the event occurred
    15. {
    16. Headeventobject.children[i].classname= "Listtablehead"//To set the ClassName property of the clicked column to Listtablehead
    17. }
    18. }
    19. var tablerows=0;
    20. Trobject=clearstart.children[0].children; Get the table row object, it's called a DataTable, maybe you wrote wrong??
    21. for (i=0;i{
    22. object=clearstart.children[0].children[i];//gets the object of each row
    23. Tablerows= (trobject[i].id== "Ignore")? tablerows:tablerows+1;//if the row is not ignored, the number of rows plus one
    24. }
    25. var trinnerhtml=new Array (tablerows);
    26. var tdinnerhtml=new Array (tablerows);
    27. var tdnumber=new Array (tablerows)
    28. var i0=0
    29. var i1=0
    30. for (i=0;i{
    31. if (trobject[i].id!= "Ignore")
    32. {
    33. trinnerhtml[i0]=trobject[i].innerhtml;//put the line in the array.
    34. tdinnerhtml[i0]=trobject[i].children[colnum].innerhtml;//the contents of TD in the row to be sorted into an array
    35. tdnumber[i0]=i;//line number
    36. i0++;//plus one, next cycle.
    37. }
    38. }
    39. sourcehtml=clearstart.children[0].outerhtml;//gets the HTML code for all TR in the table
    40. Sorting the strings in all TD is not a bubble sort???
    41. for (Bi=0;bi
    42. for (i=0;i
    43. {
    44. if (tdinnerhtml[i]>tdinnerhtml[i+1])
    45. {
    46. T_S=TDNUMBER[I+1];
    47. T_b=tdnumber[i];
    48. Tdnumber[i+1]=t_b;
    49. tdnumber[i]=t_s;
    50. TEMP_SMALL=TDINNERHTML[I+1];
    51. Temp_big=tdinnerhtml[i];
    52. Tdinnerhtml[i+1]=temp_big;
    53. Tdinnerhtml[i]=temp_small;
    54. }
    55. }
    56. }
    57. var showshow= "";
    58. var numshow= "";
    59. for (i=0;i
    60. {
    61. showshow=showshow+tdinnerhtml[i]+ "\ n";//to place the contents of the sorted TD in a Showshow string
    62. Numshow=numshow+tdnumber[i]+ ""; The corresponding line number of the order is also in Numshow
    63. }
    64. Sourcehtml_head=sourcehtml.split ("");/from truncation, I tried, and the front string was empty
    65. Numshow=numshow.split ("");
    66. var trrebuildhtml= "";
    67. if (event.srcelement.classname== "listheadclicked")
    68. {//clicked column, then inverted
    69. for (i=0;i
    70. {
    71. trrebuildhtml=trrebuildhtml+trobject[numshow[tablerows-1-i]].outerhtml;//take out the contents of the sorted TR and connect them
    72. }
    73. Event.srcelement.classname= "ListHeadClicked0";
    74. }
    75. Else
    76. {//default shun row, new click Shun Pai
    77. for (i=0;i
    78. {
    79. trrebuildhtml=trrebuildhtml+trobject[numshow[i]].outerhtml;
    80. }
    81. Event.srcelement.classname= "listheadclicked";
    82. }
    83. Gets the sorted TR collection result string
    84. var datarebuildtable= "";
    85. Connect the old table header with the new TR-sorted elements (modified)
    86. Datarebuildtable = "
    87. {
    88. "
    89. "+ trobject[0].outerhtml + trrebuildhtml +" "+
      ";
    90. clearstart.outerhtml=datarebuildtable;//table with new string write again
    91. }


      Original address: http://www.freejs.net/article_jquerywenzi_147.html

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.