Q. Write program to read directory name from user and display content of the directory.
HTML File:
<html>
<form action="a3a2.php" method="POST">
<h1>Display directory contents</h1>
<br>
<h3>Enter directory name : <input type="text" name='d'></h3>
<pre>
<input type="submit" name="submit" value="submit">
</pre>
</form>
</body>
</html>
PHP Function:
NOTE: PHP function is saved as "a3a2.php"
<?php
$d=$_POST['d'];
$h=dir(".");
if(is_dir($d))
{
$h=opendir($d);
echo "<h3><B>Directory Contents";
echo "<br/>";
while(($file=readdir($h))!==false)
{
echo "<h3>$file<br/>";
}
closedir($h);
}
else
{
echo "<center><h2><center><u>Invalid Directory or Directory does not exist!!!</u></center></h2></center>";
}
?>
HTML File:
<html>
<form action="a3a2.php" method="POST">
<h1>Display directory contents</h1>
<br>
<h3>Enter directory name : <input type="text" name='d'></h3>
<pre>
<input type="submit" name="submit" value="submit">
</pre>
</form>
</body>
</html>
NOTE: PHP function is saved as "a3a2.php"
<?php
$d=$_POST['d'];
$h=dir(".");
if(is_dir($d))
{
$h=opendir($d);
echo "<h3><B>Directory Contents";
echo "<br/>";
while(($file=readdir($h))!==false)
{
echo "<h3>$file<br/>";
}
closedir($h);
}
else
{
echo "<center><h2><center><u>Invalid Directory or Directory does not exist!!!</u></center></h2></center>";
}
?>
Output:
1 Comments
I am really enjoying reading your well-written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
ReplyDeleteDot Net Training in Chennai | Dot Net Training Institute in Chennai
Software Testing Training in Chennai | Software Testing Course in Chennai
Java Training Institute in Chennai | Core Java Training in Chennai | Java Course and Certification
PHP Course in Chennai | PHP Certification in chennai | PHP Training Institutes