-
- //filetype()
- Get the file type
- //Get the file type under windows
- echo filetype("D:\lamp\php5\php.ini")."< br>";
- //Output file means it is a normal file
- echo filetype("D:\lamp\php5")."
";
- //Output dir means it is a directory
- //is_file()
- Determine whether the given file name is a normal file
- //is_dir()
- Determine whether the given file name is a directory
- //file_exists()
- Check whether the file or directory exists
- //filesize()
- Get The size of the file
- //is_readable()
- Determine whether the given file name is readable
- //is_writable()
- Determine whether the given file name is writable
- //is_executable()
- Determine whether the given file name is executable
- //filectime()
- Get the creation time of the file
- //filemtime()
- Get the modification time of the file
- //fileatime()
- Get the access time of the file
- //stat()
- Get most of the attribute values of the file
-
- //clearstatcache()
- Clear the file information cached by PHP
- /*
- *Declare a function to get most of the attributes of the file by passing in a file name
- **/
- function getFilePro($fileName){
- if(!file_exists($fileName)){
- //If the provided file or directory does not exist, exit the function directly
- echo "The target file does not exist"."
";
- return;
- }
- if(is_file($fileName)){
- //Determine whether the given file is an ordinary file
- echo $fileName."Is an ordinary file
";
- }
- if(is_dir($fileName) ){
- //Determine whether the given file is a directory
- echo $fileName." is a directory
";
- }
- echo "File type:".getFileType($fileName)."< br />";
- echo "File size:".getFileSize(filesize($fileName))."
";
- if(is_readable($fileName)){
- //Determine whether the file is readable
- echo "The file is readable
";
- }
- if(is_writable($fileName)){
- //Determine whether the file is writable
- echo "The file is writable
";
- }
- if(is_executable($fileName)){
- //Determine whether the file is executable
- echo "The file is executable";
- }
- echo "The creation time of the file is: ".date("Y-m-d H:i:s", filectime($fileName))."
";
- echo "The last update time of the file is: ".date("Y-m-d H:i:s", filemtime($fileName))."
";
- echo "The last time the file was opened is: ".date("Y-m-d H:i:s", fileatime($fileName))."
";
- }
- /*
- *Declare a function to get the file type by passing in a file name
- */
- function getFileType($fileName){
- switch(filetype($fileName)){
- case "file":
- $type = "Ordinary file" ;
- break;
- case "dir":
- $type = "Directory file";
- break;
- case "blokc":
- $type = "Block device file";
- break;
- case "char":
- $type = "Character device file";
- break;
- case "fifo":
- $type = "Named pipe file";
- break;
- case "link":
- $type = "Symbolic link";
- break;
- case " unkonwn":
- $type = "Unknown type";
- break;
- default:
- $type = "No type detected";
- }
- return $type;
- }
- /*
- *Declare a function to convert the file Size
- */
- function getFileSize($bytes){
- if($bytes >= pow(2,40)){
- //If the number of bytes provided is greater than or equal to 2 raised to the 40th power, the condition is true
- $ return = round($bytes/pow(1024,4),2);
- //Convert bytes to the equivalent size of T
- $suffix = "TB";
- }elseif($bytes >= pow(2 ,30)){
- $return = round($bytes/pow(1024,3),2);
- //Convert bytes to the equivalent size of G
- $suffix = "GB";
- }elseif($ bytes >= pow(2,20)){
- $return = round($bytes/pow(1024,2),2);
- //Convert bytes to the equivalent size of M
- $suffix = "MB ";
- }elseif($bytes >= pow(2,10)){
- $return = round($bytes/pow(1024,1),2);
- //Convert bytes to equivalent K Size
- $suffix = "KB";
- }else{
- $return = $bytes;
- //Convert bytes to the equivalent size of B
- $suffix = "B";
- }
- return $return." " .$suffix;
- }
- getFilePro("D:\lamp\php5\php.ini");
- $filepro=stat("D:/lamp/php5/php.ini");
- //Return the size of the file Some attributes
- print_r($filepro);
- ?>
-
Copy code
|