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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 137
    Comment on it

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

    The opendir() function is used to open a directory handle.
    The opendir() function always returns a directory handle resource on succes and return FALSE on failure.

    syntax of opendir() function

    opendir(path,context);
    

    path is a required parameter
    context is a required optional

    you can see below example:

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

 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: