Home >Backend Development >PHP Problem >How to query file name in php
How to query the file name in php: You can use the pathinfo() function to query. The pathinfo() function returns information about the file path in the form of an array, including directory path, file name, etc., such as: [print_r(pathinfo("/testweb/test.txt"))].
pathinfo() function returns information about the file path in the form of an array.
(Recommended tutorial: php graphic tutorial)
The returned array elements are as follows:
[dirname]: directory Path
[basename]: file name
[extension]: file suffix name
[filename]: File name without suffix
Syntax:
pathinfo(path,options)
Parameters:
path Required. Specifies the path to be checked.
options Optional. Specifies the array elements to be returned. The default is all.
(Video tutorial recommendation: php video tutorial)
Example:
<?php print_r(pathinfo("/testweb/test.txt")); ?>
Output result:
Array( [dirname] => /testweb [basename] => test.txt [extension] => txt [filename] => test )
The above is the detailed content of How to query file name in php. For more information, please follow other related articles on the PHP Chinese website!