Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scan current folder using PHP

I have a folder structure like this:

/articles
     .index.php
     .second.php
     .third.php
     .fourth.php

If I'm writing my code in second.php, how can I scan the current folder(articles)?

Thanks

like image 232
kmunky Avatar asked Oct 29 '09 19:10

kmunky


People also ask

How to scan current directory in PHP?

php $path = new DirectoryIterator('/articles'); foreach ($path as $file) { echo $file->getFilename() . "\t"; echo $file->getSize() . "\t"; echo $file->getOwner() . "\t"; echo $file->getMTime() .

What is __ DIR __ in PHP?

The __DIR__ can be used to obtain the current code working directory. It has been introduced in PHP beginning from version 5.3. It is similar to using dirname(__FILE__). Usually, it is used to include other files that is present in an included file.

What does Scandir return?

The scandir() function returns the number of directory entries selected.

How can I get a list of all the subfolders and files present in a directory using PHP?

PHP using scandir() to find folders in a directory The scandir function is an inbuilt function that returns an array of files and directories of a specific directory. It lists the files and directories present inside the path specified by the user.


1 Answers

$files = glob(dirname(__FILE__) . "/*.php");

http://php.net/manual/en/function.glob.php

like image 101
user187291 Avatar answered Oct 30 '22 01:10

user187291