Q:

Write a program in PHP to read from directory

0

PHP Reading from Directories

Write a program in PHP to read from directory

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution

Let's implement a script to allow directory browsing of the uploaded content. Browsing directories is actually straightforward in PHP.

The following script can be used for this purpose -

<html>
<head>
<title>A divison table in PHP</title>
</head>
<body>
<?php
$current_dir = '/uploads/';
$dir = opendir($current_dir);

echo '<p>Upload directory is $current_dir</p/>';
echo '<p>Directory Listing:</p>';
echo '<ul>';
while($file = readdir($dir))
{
echo "<li>".$file."</li>"
}
echo '</ul>';
closedir($dir);
?>
</body>
</html>

The PHP function opendir() opens a directory handle. It takes directory path as parameter that to be opened. The readdir() function read from directory handle. The entries are returned in the order in which they are stored by the filesystem. The closedir() function is used to close a directory handle that is opened by the opendir() function.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now