Get the App
SLTechnology News&Howtos  ›  Development  › 

How to query the files in the directory by php

Shulou Source: shulou.com Published: 2022-06-02 09:39:31 10月29日 Update

This article will explain in detail how php queries the files under the directory, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

PHP query directory file method: 1, create a PHP sample file;2, get the parent directory of the current file;3, through the "scandir($con);" scan all files under the $con directory can be.

Operating environment: Windows 7 system, PHP7.1 version, DELL G3 computer

PHP Gets all files in the current directory

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

//Get the parent directory of the current file $con = dirname(__FILE__);//Scan all files in the $con directory $filename = scandir($con);//Define an array to receive file names $conname = array();foreach($filename as $k=>$v){ //skip two special directories continue Jump out of the loop if($v==". " || $v==".. "){continue;} //truncate the file name, I only need the file name without suffix; then store it in the array. If you need a direct suffix $v then $conname[] = substr($v,0,strpos($v,". "));}

About "php how to query files under the directory" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Tags: File directory file name query article superior suffix array method more reference good practical special two content that is article sometimes environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Xiaomi Apple NVidia Linux