What are some PHP functions that can be used to list files in a directory and their properties?
To list files in a directory and their properties in PHP, you can use functions like `scandir()` to get a list of files in a directory and `filemtime()` to get the last modification time of a file. You can also use `filesize()` to get the size of a file in bytes. By combining these functions, you can create a script that lists files in a directory along with their properties.
$directory = "/path/to/directory";
$files = scandir($directory);
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
$filePath = $directory . '/' . $file;
$fileSize = filesize($filePath);
$fileLastModified = date("Y-m-d H:i:s", filemtime($filePath));
echo "File: $file | Size: $fileSize bytes | Last Modified: $fileLastModified <br>";
}
}
Keywords
Related Questions
- What are some best practices for handling form submissions and processing variables in PHP to avoid issues like the one described in the forum thread?
- How can the caching mechanism in the PHP code be optimized for better performance?
- What are the potential pitfalls of mixing PHP and HTML code in a single file?