Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

PHP scandir() Function

by
Category:php
php
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. You may also like How to Copy file from one folder to another folder using PHP and How to get file size in PHP.

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;
       }
   }
?>

0 Comments


Html code work in comment box


Related Post