Suppose there is an image file now, and its server-side path is:
$path = "/www/mywebsite/images/myphoto.jpg";
1.pathinfo() function
The pathinfo() function returns an array containing file information. There are four elements in the array, namely dirname, basename, extension, and filename. Code to print array:
Copy 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 get the corresponding key value just based on the key name of the array:
Copy code The code is as follows:
echo $fileArr['filename'];
//Output result: myphoto
echo $fileArr['extension'];
//Output result: jpg
//...
2.dirname() function dirname() function gives a character containing the full path to a file string, the value it returns is the directory name after removing the file name, which can be considered as an extension of the pathinfo() function:
Copy code 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 results are: /www/mywebsite
So it can be understood that the returned value is the path The address name of the upper-level directory.
3.basename() function
The basename() function gives a string containing the full path to a file. The value it returns is the basic file name, which can also be considered It is an extension of the pathinfo() function:
Copy code The 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 returned value is the name of the current directory of the path.
http://www.bkjia.com/PHPjc/324253.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324253.htmlTechArticleSuppose there is an image file and its server-side path is: $path = "/www/mywebsite/images /myphoto.jpg"; 1.pathinfo() function The pathinfo() function returns a file containing the file information...