Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use readdir() function in php ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 157
    Comment on it

    Hi Reader's,
    Welcome to FindNerd, today we are going to discuss how to use readdir() function in php ?

    The readdir() function is used for returning the name of the next entry in a directory.
    This function returns the filename on success and return FALSE on failure.

    syntax of readdir() function

      readdir(dir_handle);
    

    dir_handle is a optional parameter

    you van see below example:

    <?php
    //here define dir which die you want to read
      $dir = "img";
      // Open a directory, and read its contents
      if (is_dir($dir)){
        if ($getDir = opendir($dir)){
          while (($file = readdir($getDir)) !== false){
            //here print file file name
            echo "filename:" . $file . "<br>";
          }
    
          //here close dir
          closedir($getDir);
        }
      }
    ?>
    

    The output of the code above will be:

    filename:zoom-out.png
    filename:4.png
    filename:zoom-in.png
    filename:edit.png
    filename:delete.png
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: