PHPpathinfo () obtains the file path, name, and other information descriptions. Suppose there is an image file, and its server path is: export pathwwwmywebsiteimagesmyphoto.jpg; 1. the pathinfo () function, pathinfo (), returns an image file containing a file. assume that there is an image file, and its server path is:
$ Path = "/www/mywebsite/images/myphoto.jpg ";
1. pathinfo () function
The pathinfo () function returns an array containing file information. the array contains four elements: dirname, basename, extension, and filename. Print the array code:
The code is as follows:
$ FileArr = pathinfo ($ path );
Print_r ($ fileArr );
// Output result: Array ([dirname] =>/www/mywebsite/images [basename] => myphoto.jpg [extension] => jpg [filename] => myphoto)
In this way, we can obtain the corresponding key value based on the array key name:
The code is as follows:
Echo $ fileArr ['filename'];
// Output result: myphoto
Echo $ fileArr ['extension'];
// Output result: jpg
//...
2. dirname () function
The dirname () function provides a string containing a full path to a file. the returned value removes the directory name after the file name. it can be considered an extension of the pathinfo () function:
The code is as follows:
Echo dirname ($ path );
// Output result:/www/mywebsite/images
// Or
Echo dirname ("/www/mywebsite/images /");
Echo dirname ("/www/mywebsite/images ");
// The output result is/www/mywebsite.
Therefore, it can be understood that the returned value is the directory address name at the top layer of the path.
3. basename () function
The basename () function provides a string containing a full path pointing to a file. the returned value is the basic file name. it can also be considered an extension of the pathinfo () function:
The code is as follows:
Echo basename ($ path );
// Output result: myphoto.jpg
// Or
Basename ("/www/mywebsite/images /");
// Output result: images
Therefore, it can be understood that the returned value is the name of the current directory of the path.
Export $ path = "/www/mywebsite/images/myphoto.jpg"; 1. the pathinfo () function returns a file containing a letter...