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
php $path = new DirectoryIterator('/articles'); foreach ($path as $file) { echo $file->getFilename() . "\t"; echo $file->getSize() . "\t"; echo $file->getOwner() . "\t"; echo $file->getMTime() .
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.
The scandir() function returns the number of directory entries selected.
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.
$files = glob(dirname(__FILE__) . "/*.php");
http://php.net/manual/en/function.glob.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With