Loading...
PHP

Directory Function Supported By PHP

mkdir: By using this function we can create directory
<?php
mkdir(“abc”);
?>

rmdir:  To remove the existing directory.
<?php
rmdir(“abc”);
?>

opendir: To open contents of directory.

readdir: To read the files of a directory.

closedir: To close open directory
Example:
1.. To open and read all xampp folder files and print those files
<?php
$dh=opendir(“c:/xampp”);
while($file=readdir($dh))
{
echo $file;
echo “<br>”;
}
?>

2. To open .txt file
<?php
$dh= opendir(“c:/xampp”);
while($file=readdir($dh))
{
$ext=strrch($file, “.”);
if($ext== ==”.txt”){
echo $file;
echo “<br>”;
}
}
?>

scandir: To read the all files and returns those files as array elements.
<?php
print_r(scandir(“c:/”));
echo “<br>”;
?>

Leave a Reply

Your email address will not be published. Required fields are marked *