Suppose you now have a picture file whose server-side path is:
$path = "/www/mywebsite/images/myphoto.jpg";
1.pathinfo () function
The PathInfo () function returns an array containing the file information, with four elements, dirname, basename, extension, and filename, respectively. Print the code for the array:
Copy CodeThe code is as follows:
$FILEARR = PathInfo ($path);
Print_r ($FILEARR);
Output: Array ([dirname] =/www/mywebsite/images [basename] = myphoto.jpg [extension] = jpg [filename] = m Yphoto)
This allows us to obtain the corresponding key value based on the key name of the array:
Copy CodeThe code is as follows:
echo $fileArr [' filename '];
Output Result: Myphoto
echo $fileArr [' extension '];
Output result: JPG
//...
2.dirname () function
The dirname () function gives a string containing a full path to a file, and the value returned removes the directory name after the file name, which can be considered an extension of the PathInfo () function:
Copy CodeThe code is as follows:
echo dirname ($path);
Output Result:/www/mywebsite/images
Or
Echo dirname ("/www/mywebsite/images/");
Echo dirname ("/www/mywebsite/images");
The result of the output is:/www/mywebsite
So it can be understood that the returned value is the previous level directory address name of the path.
3.basename () function
The basename () function gives a string containing a full path to a file, and the value returned is a basic file name, which can also be considered an extension to the PathInfo () function:
Copy CodeThe code is as follows:
Echo basename ($path);
Output Result: myphoto.jpg
Or
BaseName ("/www/mywebsite/images/");
Output Result: Images
So it can be understood that the return value is the name of the path of the current directory.
http://www.bkjia.com/PHPjc/324253.html www.bkjia.com true http://www.bkjia.com/PHPjc/324253.html techarticle Suppose you now have a picture file whose server-side path is: $path = "/www/mywebsite/images/myphoto.jpg"; The 1.pathinfo () function pathinfo () function returns a file containing a letter ...