The file operations mentioned here are mainly about how php obtains the main information of a file, determines the nature of the file, and obtains the file name and directory name. The following figure shows the code of the three instances. copy the code to obtain the main information of the file...
The file operations mentioned here are mainly about how php obtains the main information of a file, determines the nature of the file, and obtains the file name and directory name. See the following three instances.
The code is as follows: |
|
// Obtain the main information of the object. $ File = "data.txt "; If (is_dir ($ file )) { Echo "file $ file is a directory "; Echo" "; } Else { Echo "file $ file is not a directory "; Echo" "; } If (is_file ($ file )) { Echo "file $ file is a common file "; Echo" "; } If (is_readable ($ file )) { Echo "file $ file is readable "; Echo" "; } Else { Echo "file $ file is unreadable "; Echo" "; } If (is_writeable ($ file )) { Echo "file $ file is writable "; Echo" "; } Else { Echo "file $ file is not writable "; Echo" "; } // Determine the object nature. $ Path = "/home/prog/php/sayhello. php "; $ File_name = basename ($ path ); $ Dir_name = dirname ($ path ); Echo "full path:". $ path; Echo ""; Echo" "; Echo "the directory name is:". $ dir_name; Echo" "; Echo "where the file name is:". $ file_name; Echo" "; // Obtain the file name and directory name. $ File = "data.txt "; $ Dir = "info/newdata "; If (file_exists ($ file )) { Echo "in the current directory, the file". $ file. "exists "; Echo" "; } Else { Echo "current directory, file". $ file. "does not exist "; Echo" "; } Echo" "; Echo ""; Echo" "; If (file_exists ($ dir )) { Echo "the current directory, Directory". $ dir. "exists "; Echo" "; } Else { Echo "directory under the current directory". $ dir. "does not exist "; Echo" "; } |
Article URL:
Reprint ^ at will, but please attach the tutorial address.