PHP remote file management, can give table sorting, traversal directory, time sorting _php tips

Source: Internet
Author: User

Copy Code code as follows:

<?php
$rootdir = "./";
$spacenum = 0;
$filenum = 0;
$allfilesize = 0;
echo "echo "<a href= ' > Reset </a>";
Readlogdir ($rootdir);
echo "echo "Total files Count: $filenum .<br>";
echo "Total disk space used: $allfilesize <br>";
$freespace =diskfreespace ("/");
echo "Residue disk space: $freespace <br>";
function Readlogdir ($subdir) {
Global $rootdir, $spacenum, $filenum, $allfilesize;
@chdir ($subdir) or Die ("Error:could not on" to this directory!);
$dirobject =dir ($subdir);
echo "<table width=600 border=0 align= ' center ' id= ' Clearstart ' ><tr ' the id= ' Ignore ' ><td's width=40% ' Jm_powerlist (0) ' ><b> filename </b></a></td><td width=20% onclick= ' jm_powerlist (1) ' > <b> File size </b></td><td width=40% onclick= ' jm_powerlist (2) ' ><b> creation time &LT;/B&GT;&LT;/TD ></tr> ";
$i = 0;
while ($file = $dirobject->read ()) {
if ($file = = "." | | $file = = "...") {
Continue
}
$i = $i +1;
echo "<tr bgcolor= ' #e0e0e0 ' ><td>". $i. " <a href=.php?file_dir= ". $rootdir." &file_name= ". $file." Target=_blank> ";
echo $file. " </a></td><td> ". Number_format (FileSize ($file)/1024, 2, '. ', '). " Kb</td><td> ". Date ("Y-m-d h:i:s", Filemtime ($file)). "</td></tr>";
$allfilesize +=filesize ($file);
$filenum + +;
}
echo "</table>";
Return
}
?>
<script src= "Table_sort.js" ></script>
Required JS file
/**
* Table Sort
* Anthor Liueh
*/
function Jm_powerlist (colnum)
{
headeventobject=event.srcelement;//to get the object that raised the event
while (headeventobject.tagname!= "tr")//is not a TR line, the following TD bubbles up to find the appropriate 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 property of the clicked column to Listtablehead
}
}
var tablerows=0;
Trobject=clearstart.children[0].children; Get the table row object, it's called a DataTable, maybe you wrote wrong??
for (i=0;i<trobject.length;i++)
{
object=clearstart.children[0].children[i];//gets the object of each row
tablerows= (trobject[i].id== ' Ignore ')? tablerows:tablerows+1;//if the row is not ignored, the number of rows plus one
}
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<trobject.length;i++)
{
if (trobject[i].id!= ' ignore ')
{
trinnerhtml[i0]=trobject[i].innerhtml;//put the line in the array.
tdinnerhtml[i0]=trobject[i].children[colnum].innerhtml;//the contents of TD in the row to be sorted into an array
tdnumber[i0]=i;//line number
i0++;//plus one, next cycle.
}
}
sourcehtml=clearstart.children[0].outerhtml;//gets the HTML code for all TR in the table
Sorting the strings in all TD is not a bubble sort???
for (bi=0;bi<tablerows;bi++)
{
for (i=0;i<tablerows;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<tablerows;i++)
{
showshow=showshow+tdinnerhtml[i]+ ' \ n ';//to place the contents of the sorted TD in a Showshow string
numshow=numshow+tdnumber[i]+ ' | '; The corresponding line number of the order is also in Numshow
}
Sourcehtml_head=sourcehtml.split ("<TBODY>");//from <TBODY> truncated, I tried, the front string is empty
Numshow=numshow.split ("|");
var trrebuildhtml= ';
if (event.srcelement.classname== ' listheadclicked ')
{//clicked column, then inverted
for (i=0;i<tablerows;i++)
{
trrebuildhtml=trrebuildhtml+trobject[numshow[tablerows-1-i]].outerhtml;//take out the contents of the sorted TR and connect them
}
Event.srcelement.classname= ' listHeadClicked0 ';
}
Else
{//default shun row, new click Shun Pai
for (i=0;i<tablerows;i++)
{
trrebuildhtml=trrebuildhtml+trobject[numshow[i]].outerhtml;
}
Event.srcelement.classname= ' listheadclicked ';
}
Gets the sorted TR collection result string
var datarebuildtable= ';
Connect the old table header with the new TR-sorted elements (modified)
datarebuildtable = "<table border=0 width=600 id= ' clearstart ' align= ' center ' ><TBODY>" + trobject[0]. outerHTML + trrebuildhtml + "</TBODY>" +
"</table>";
clearstart.outerhtml=datarebuildtable;//table with new string write again
}

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.