Recalling the basic code framework listed in section III, the author has reserved a number of headers for enumerating file property information:
echo "<table>", echo "<tr><th>name</th><th>type</th><th>readable</th ><th>writable</th><th>excutable</th><th>size</th><th>created</ Th><th>modified</th><th>access</th><th>operation</th></tr> ";
Such as:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/59/C6/wKioL1ThlziwwGNSAAEcAQf4X-M397.jpg "title=" PHP File Manager 4.png "alt=" Wkiol1thlziwwgnsaaecaqf4x-m397.jpg "/>
From left to right are name, type, readability, writable, executable, size, creation time, modification time, access time, operation. The type is folder, file, connection, etc., readable, writable, executable by the checkmark and the wrong number icon to identify true or False. The size provides an approximate amount, create, modify, access time to provide a standard time representation, and the Action bar lists the actions that can be performed on the element.
Specific to the file, the contents of each line are listed by the Getfileeleminfo function:
if (Isset ($fileList)) {$isDirEmpty = false; Natsort ($fileList); foreach ($fileList as $fileName) {echo getfileeleminfo ($strDirName, $fileName); } }
With Natsort, you can provide a more reasonable sort pattern for file names. If you need a more complex sort, you can use Usort, which does not expand here.
The stat () function can be used to get more properties of the file, and the file type can be obtained by filetype.
Here's how to describe the first two items:
function Getdireleminfo ($dirPath, $elemName) {$dirPath = RTrim ($dirPath, "/"); $filePath = $dirPath. " /". $elemName; if (! ( $res = stat ($filePath))) return ""; $info = "<tr>"; $elemType = filetype ($filePath) $info. = "<td class=\" filename\ ">". $elemName. " </td> "; $info. = "<td>". $elemType. " </td> ";
The $info variable holds the entire line of information and continues to be used.
The following three functions can be used to get the values of the next three columns:
Readable: is_readable
Writable: is_writable
Executable: is_executable
However, the result is a bool value that needs to be translated into a specific image link. The following is used?: Ternary operator concise implementation of this function.
$pathCorrect = "Images/correct.png"; $pathError = "Images/error.png"; $pathReadable = is_readable ($filePath)? $pathCorrect: $pathError; $info. = "<td class=\" sig\ "></td>"; $pathWritable = is_writable ($filePath)? $pathCorrect: $pathError; $info. = "<td class=\" sig\ "></td>"; $pathExcutable = is_executable ($filePath)? $pathCorrect: $pathError; $info. = "<td class=\" sig\ "></td>";
Note the style of the sig that it uses, the corresponding CSS is:
. Sig{text-align:center;}
You can center the icon in the display.
Using FileSize or stat () ["size"] can get a byte-based file size, but that is too redundant, so I wrote the following sizetobytes function to give the relative size of the file:
function Sizetobytes ($size) {$listUnits = Array ("Bytes", "Kb", "Mb", "Gb", "Tb"); $index = 0; $base = 1; while ($size >= $base * 1024x768) {$base *= 1024; $index + +; } return sprintf ("%.2f%s", $size/$base, $listUnits [$index]);} $info. = "<td>". Sizetobytes ($res ["size"]). " </td> ";
File creation, modification, access time can be listed in the following ways
$info. = "<td>". Date ("Y-m-d h:m:s", $res ["CTime"]). " </td> "; $info. = "<td>". Date ("Y-m-d h:m:s", $res ["Mtime"]). " </td> "; $info. = "<td>". Date ("Y-m-d h:m:s", $res ["Atime"]). " </td> ";
In fact, many of the above functions apply to the properties of a folder in addition to the file size.
Specific effects:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/59/C6/wKioL1Thm4vA4ZbqAAJb0f6JtJ0411.jpg "title=" PHP File Manager 5.png "alt=" Wkiol1thm4va4zbqaajb0f6jtj0411.jpg "/>
This article is from the "Accplayer Small Place" blog, make sure to keep this source http://accplaystation.blog.51cto.com/9917407/1614667
PHP Server File Manager Development Summary (v): Get file property Information