Home >Backend Development >PHP Problem >How to query file name in php

How to query file name in php

王林
王林Original
2020-08-05 16:16:322755browse

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"))].

How to query file name in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn