-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblogs.php
63 lines (55 loc) · 1.87 KB
/
blogs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<html>
<body>
<center><h1><center>Ken Elliott's Micro Blog</h1>
----------------------------------------------------<br><br><br>
<table width="75%" align='center' style="border-left: 1px solid #cdd0d4;border-right: 1px solid #cdd0d4;padding-left: 30px;padding-right: 30px;"><tr><td>
<?php
// Set the directory path
$dir = getcwd();
$dir2 = "/blogs/";
$dir3 = $dir.$dir2;
$colors = array("blue","purple","green","red","yellow","orange");
$colorCount = 0;
// Set the directory path
$dir = 'path/to/directory';
// Check if the directory exists and is accessible
if (!is_dir($dir3)) {
die("The directory $dir does not exist or is not accessible.");
}
// Get all the text files in the directory
$files = glob("$dir3/*.txt");
// Sort the files by newest date
usort($files, function($a, $b) {
return filemtime($b) - filemtime($a);
});
// Loop through all files in the directory
foreach ($files as $file) {
// Check if the file is readable
if (!is_readable($file)) {
echo "The file $file is not readable.";
continue;
}
// Open the text file
$text = file_get_contents($file);
// Display the text as HTML and add some ad hoc HTML tags and flair
echo "</td></tr><tr><td>";
//Set the size of your headers from your text file
echo "<font size='6' color='$colors[$colorCount]'>";
// remove the .txt from the display header
$name = rtrim($file, ".txt");
// remove the directory path from the display header
$name = ltrim($name, "/var/www/html/blogs");
echo $name;
echo "</font></td><td align=left>";
// get date and time of the text document and remove time with substring
echo "<script>x = document.lastModified;
document.write(x.substring(0,x.length-8));</script></td></tr><tr><td><br>";
echo nl2br($text);
// add break so there is spacing between entries
echo "<br><br>";
$colorCount++;
}
?>
</td></tr></table>
</body>
</html>