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

How to query file name in php

王林
Release: 2023-03-03 20:48:01
Original
2769 people have browsed it

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)
Copy after login

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"));
?>
Copy after login

Output result:

Array(
    [dirname] => /testweb    
    [basename] => test.txt    
    [extension] => txt    
    [filename] => test
)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template