How do I examine directories with PHP?

Author Topic: How do I examine directories with PHP?  (Read 838 times)

Offline chinmay.sahooTopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 2
  • Posts: 159
  • Karma: 0
    • Hot Shaper
How do I examine directories with PHP?
« on: 07-08-2016, 06:59:31 »
When you’re creating web-based file managers in PHP, it’s handy to be able to explore the contents of directories.

Solutions

There are two basic approaches to examining directories with PHP—you should use whichever method you prefer.7

Using the readdir Function

The first approach, which uses the opendir, readdir, and closedir functions, is similar to the process of using fopen , fread, and fclose to read a file:

Quote
<?php
$location = './';
$dp =
opendir($location)
;
while ($entry =
readdir($dp)
)
{
if (is_dir($location . $entry))
{
echo '[Dir] ' . $entry . '<br />';
}
else if (is_file($location . $entry))
{
echo '[File] ' . $entry . '<br />';
}
}
closedir($dp)
;
?>


 

Related Topics

  Subject / Started by Replies Last post
5 Replies
2650 Views
Last post 02-29-2012, 08:46:56
by mmchandana
4 Replies
2938 Views
Last post 01-02-2013, 23:23:32
by abhirampathak3
2 Replies
2571 Views
Last post 09-29-2016, 06:19:03
by kaufenpreis
3 Replies
1823 Views
Last post 03-30-2016, 20:32:11
by hainvv
0 Replies
1901 Views
Last post 08-04-2012, 04:28:49
by dgl