1) 1.php
<html>
<head>
</head>
<body>
<?
// if form has not been submitted, display form
if (!$submit)
{
?>
<center>
<form action=<? echo $PHP_SELF; ?> method=post>
Enter location: <input type=text name=location size=15>
<input type=submit name=submit value="Go">
</form>
</center>
<?
}
else
{
// change to directory
$res = chdir($location);
// if chdir() successful
if ($res)
{
// get directory handle
$hook = dir($location);
// display location
echo "<b>Current path is $hook->path</b><br>";
// read directory and echo list
while ($file=$hook->read())
{
if ($file != "." && $file != "..")
{
echo "$file<br>";
}
}
// close directory
$hook->close();
}
else
{
// display error
echo "<b>Unable to locate directory $location</b><br>";
}
}
?>
</body>
</html>
2.2.php
<?
// get directory handle
$hook = dir("c:/php");
// display location
echo "<b>Current path is $hook->path</b><br>";
// read directory and echo list
while ($file=$hook->read())
{
echo "$file<br>";
}
// close directory
$hook->close();
?>
|