Home >Backend Development >PHP Tutorial >PHP file management, you can click to sort by time, size, name_PHP tutorial

PHP file management, you can click to sort by time, size, name_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:29:551093browse

php file management, you can click to sort by time, size, name

This example does not use jquery

PHP file management, you can click to sort by time, size, name_PHP tutorialDemo

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 change to this directory !");
  16. $dirobject=dir($subdir);
  17. echo "";
    File name File size Creation time
    ";
  18. $i=0;
  19. while ($file=$dirobject->read()){
  20. if($file=="." || $file==".."){
  21. continue;
  22. }
  23. $i=$i+1;
  24. echo "
  25. ";
  26. $allfilesize+=filesize($file);
  27. $filenum++;
  28. }
  29. echo "
  30. 文件名 文件大小 创建时间
    ".$i."";
  31. echo $file."
  32. ". number_format((filesize($file)/1024),2,'.','')."KB ". date("Y-m-d H:i:s", filemtime($file)). "
    $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 "";
  33. return;
  34. }
  35. ?>
  36. JavaScript Code
    1. /**
    2. * table sorting
    3. * anthor liueh
    4. */
    5. function JM_PowerList(colNum)
    6. {
    7. headEventObject=event.srcElement;//Get the object that triggered the event
    8. while(headEventObject.tagName!=" TR") //If it is not the tr line, then bubble up from the td below to find the corresponding line
    9. {
    10. headEventObject=headEventObject.parentElement;
    11. }
    12. for (i=0; i{
    13. if (headEventObject.children[i]!=event.srcElement)//Find 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 that this is called DataTable. 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 not Ignore rows, then 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 rows in the array
    33. tdinnerHTML[i0]=trObject[i].children[colNum].innerHTML;/ /Put the contents of td in the row to be sorted into the array
    34. tdNumber[i0]=i; //Row number
    35. i0++; //Add one, use
    36. }
    37. } sourceHTML=clearStart.children[0].outerHTML;//Get the html code of all tr ​​in the table
    38. //Sort the strings in all td, is it considered bubble sort???
    39. for (bi=0;bi{ {
    40. for (i=0;i{
    41. if(tdinnerHTML[i]>tdinnerHTML[i+1])
    42. {
    43. t_s=tdNumber[i+1];
    44. t_b=tdNumber[i];
    45. tdNumber[i+1]=t_b;
    46. tdNumber[i]=t_s;
    47. temp_small=tdinnerHTML[i+1];
    48. temp_big=tdinnerHTML[i];
    49. tdinnerHTML[i+1]=temp_big;
    50. tdinnerHTML[i]=temp_small;
    51. }
    52. }
    53. }
    54. var showshow='';
    55. var numshow='';
    56. for (i=0;i{
    57. showshow=showshow+tdinnerHTML[i]+'n';//把排序好的td的内容存在showshow字串里
    58. numshow=numshow+tdNumber[i]+'|'; //把排序好的相应的行号也存在numshow中
    59. }
    60. sourceHTML_head=sourceHTML.split("");//从 截断,我试了,前头串为空
    61. numshow=numshow.split("|");
    62. var trRebuildHTML='';
    63. if (event.srcElement.className=='listHeadClicked')
    64. {//已点击的列, 则逆排
    65. for (i=0;i{
    66. trRebuildHTML=trRebuildHTML+trObject[numshow[tableRows-1-i]].outerHTML;//取出排序好的tr的内容连接起来
    67. }
    68. event.srcElement.className='listHeadClicked0';
    69. }
    70. else
    71. {//默认顺排,新点击顺排
    72. for (i=0;i{
    73. trRebuildHTML=trRebuildHTML+trObject[numshow[i]].outerHTML;
    74. }
    75. event.srcElement.className='listHeadClicked';
    76. }
    77. //取得排序后的tr集合结果字符串
    78. var DataRebuildTable='';
    79. //把旧的表格头和新的tr排序好的元素连接起来, (修改了一下)
    80. DataRebuildTable = "" + trObject[0].outerHTML + trRebuildHTML + "" +
    81. "
    82. 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 + "" + "
      ";
    83. clearStart.outerHTML=DataRebuildTable;//Rewrite the table with a new string
    84. }


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

      www.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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn