Home  >  Article  >  Backend Development  >  How to use php readdir function

How to use php readdir function

藏色散人
藏色散人Original
2019-02-20 10:41:403237browse

php The readdir function is used to read entries from a directory handle. Its syntax is "readdir(dir_handle)". If successful, it returns the entry name, and if it fails, it returns FALSE.

How to use php readdir function

#php How to use the readdir function?

php readdir() function syntax

Function: Return the file name of the next file in the directory.

Syntax:

readdir(dir_handle)

Parameters:

dir_handle Optional. Specifies a directory handle resource previously opened by opendir(). If this parameter is not specified, the last link opened by opendir() is used.

Description:

If successful, return the entry name (file name), otherwise return FALSE.

php readdir() function usage example

<?php
$dir = "/phpstudy/WWW/20180414/";
// 打开目录,然后读取其内容
if ($dh = opendir($dir)){
        while (($file = readdir($dh)) !== false)
        {
            echo "filename:" . $file . "<br>";
        }
}
?>

This article is an introduction to the PHP readdir function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use php readdir function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn