> Online tutorial : read directory php
Showing posts with label read directory php. Show all posts
Showing posts with label read directory php. Show all posts

delete directory in php

delete directory in php



<?php
// delete a new directory path
rmdir("C:\wamp\www\uploaddata1");
if(rmdir)
{
    echo "directory removed";
}
else
{
    echo "directory can't removed";
}
?>


output:
before





After the code

create directory in php

create directory in php
Now we are going to create directory that is folder in php.In the PHP we are having mkdir()to create directory.

Program

<?php
// create a new directory path
mkdir("C:\wamp\www\uploaddata1");
if(mkdir)
{
    echo "directory created";
}
else
{
    echo "directory can't created";
}
?>


Output


In this program we are create directory called uploaddata will created .

read directory php

read directory php
<?php
// assign folder into variable
$currdir='/var/www';
//open the directory for reading $dir=opendir($currdir);
//read a filename
while($file = readdir($dir)
{
// Display all file name in the specified folder
echo "$file<br/>";
}
closedir($dir);
}?>
Output:

index.html
est.html
first.php

Explanation
Now opendir simply opens a directory,replace folder with the name of the folder and if needed, the path too.The while loop then goes through file by file in the directory .the if statement exclude s showing two non-files.you can exclude any files you wish too.After a simpl e echo displaying the filename