How to query files in a directory with php

藏色散人
Release: 2023-03-14 08:08:01
Original
9068 people have browsed it

How to query files in a directory with php: 1. Create a PHP sample file; 2. Get the upper-level directory of the current file; 3. Scan all files in the $con directory through "scandir($con);" Just file.

How to query files in a directory with php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How does php query the files in the directory?

PHP Get all the files in the current directory

We sometimes want to get all the file names in the current directory. The following is a method I wrote, please refer to it

// 获取当前文件的上级目录 $con = dirname(__FILE__); // 扫描$con目录下的所有文件 $filename = scandir($con); // 定义一个数组接收文件名 $conname = array(); foreach($filename as $k=>$v){ // 跳过两个特殊目录 continue跳出循环 if($v=="." || $v==".."){continue;} //截取文件名,我只需要文件名不需要后缀;然后存入数组。如果你是需要后缀直接$v即可 $conname[] = substr($v,0,strpos($v,".")); }
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to query files in a directory with php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!