Home >Backend Development >PHP Tutorial >php browse directory_PHP tutorial
The opendir() function opens a directory handle and can be used by closedir(), readdir() and rewinddir(). If successful, the function returns a directory stream, otherwise it returns false and an error. You can hide error output by prepending "@" to the function name.
php tutorial browse directory
The opendir() function opens a directory handle and can be used by closedir(), readdir() and rewinddir().
If successful, this function returns a directory stream, otherwise it returns false and an error. You can hide error output by prepending "@" to the function name.
*/
$dir = opendir("images");
//List files in the images directory
while (($file = readdir($dir)) !== false)
{
echo "filename: " . $file . "
";
}
closedir($dir);
// Take a look at the modified directory browsing implementation and use the table to browse the structure of the directory
print("n");
n");
//Create the header of the table
print("n"); n");
print("File name n");
print("File size n");
print("
$mydirectory = opendir("."); // Create a handle to the operating directory
// Read each sub-item in the directory
while($entryname = readdir($mydirectory))//Access each file in the directory through loop
{
Print(""); n");
Print("$entryname ");
Print(""); ");
Print(filesize($entryname));//Return file size
Print("
Print("
}
closedir($mydirectory); // Close the directory
print("