How can PHP be used to display the contents of a local file system on a website?
To display the contents of a local file system on a website using PHP, you can use the `scandir()` function to get a list of files and directories in a specified directory. You can then loop through the array of files and directories and display them on the webpage.
<?php
$dir = '/path/to/directory/';
// Check if the directory exists
if(is_dir($dir)){
// Get list of files and directories
$files = scandir($dir);
// Loop through the array and display each file or directory
foreach($files as $file){
echo $file . "<br>";
}
} else {
echo "Directory not found";
}
?>
Keywords
Related Questions
- How can PHP be used to search through multiple files in a folder on a server for specific text or numbers?
- What are the benefits of using a wrapper to encapsulate database access in PHP?
- What are the potential issues with assigning the correct images and titles to objects in PHP when data is passed from a form?