How do I make the folders and directories on my disk appear on my Web page? So take a look at how PHP is going to manipulate them.
PHP files, typically containing two pieces of content, files and directories
First, a sentence to see the code, and his role
Look at the results after running
File refers to the meaning of a document
Change the path again.
After running
Dir Here is a shorthand for the directory.
In fact, the type of file to determine the two, is the file or directory
The paths written here are the files and directories that are built in the current directory,
wenjiancaozuo.php is the file name of the current write code
Qq.txt 111.php These three are all in the same directory, if you want to write, you can have the name of a random
Keep looking.
The previous code said that Dir is a shorthand for the directory, after judging the type of file 111.php is the directory, then run this code, see what he will return the content it
and see what values the non-directory will return.
If you replace dir with file in the previous sentence, you can also mean that the file is not a file, that is, it returns true, and it returns false.
And then again. File properties
What is a file attribute? Let's take a look at the picture.
Like this, it's called file attributes.
Or a sentence to see the code
Still need a path to the file
It's qq.txt.
Look at the results after the run
The result is a timestamp.
Turn it into something you can read.
Using the Date method
Look at the results of the operation
And the time shown in the file is the same.
Look again.
And the last sentence is a letter, the result of the operation and the previous access time is the same
This one is a letter, and the result is the same as the above two times.
Look at the results of the operation
There is no content in the file, so the file size is 0
Next, enter the content, and then look at the results of the operation.
Then run the code just now, and the result is:
This file is there, run it and see what it will return.
Write a non-existent file path and see what value will be returned.
After running
Say the file path
Run for a minute
Shows the root path of the server
This is a file from the parent directory.
After running
The file name is displayed.
BaseName also has a usage that can write two parameters
Look at the results of the run
Look at the results of the operation
Minus the file name, two points left.
After running
Returned is an array of
Look at the results of the operation
Look at the results of the operation
Depending on the parameters within the parentheses, the returned results will be different.
Like what:
This is the suffix that is found in. txt.
The file that is found here is the suffix of the. php
You can use the above traversal method, the 111.php directory of files are traversed out
Look at the results of the operation
Look at the results of the run
Check to see if the results are 5 right.
3+2 the result is 5.
Look at the results of this run
All files in the current directory
If you want to get a file name with a path, you can write this
Look at the results of the run
There's one on the top. and. Here's a note.
. Represents the current directory: represent the parent directory
In general, take care to get rid of those two rows.
//get the size of all files in a directoryfunctionFsize ($fname){ $size= 0; $dir=Opendir($fname); while($u=Readdir($dir)) { if($u=="." ||$u=="..") { } Else { $zfname=$fname." /".$u; if(Is_file($zfname)) { $size+=filesize($zfname); } } } //find subdirectories, get the file size under subdirectories Rewinddir($dir); while($u=Readdir($dir)) { if($u=="." ||$u=="..") { } Else { $zfname=$fname." /".$u; if(Is_dir($zfname)) { $size+ = Fsize ($zfname); } } } Closedir($dir); return $size;}EchoFsize ("./111.php");
This is the size of the fetch file.
To run it.
Verify
and find a file with the content.
Change the path to this and look at the results of the operation.
To verify
OK, tomorrow we will send you the file operation (below), you can use the code to complete the file additions and deletions
Working with PHP on the file (above)