PHP scandir() Function

The scandir() function returns an array of files and directories of the specified directory. Required. Specifies the directory to be scanned and follow below example.

Example

<?php
    $dir = "ipafiles/";
    $cdir = scandir($dir);
    echo "<pre>";
    print_r($cdir);
?>

Output

Array
(
    [0] => .
    [1] => ..
    [2] => ifl2ux.ipa
    [3] => iflux.ipa
)

Get data using foreach loop

<?php
   $dir = "ipafiles/";
   $cdir = scandir($dir);
   foreach ($cdir as $key => $value)
   { 
       if (!in_array($value,array(".","..")))
       {  
           echo $value;
       }
   }
?>

Leave a Reply

Your email address will not be published. Required fields are marked *