Code: Select all
<?php
function curPageURL()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on")
{
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
{
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else
{
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
print('Currently Browsing ');
echo curPageURL();
///makes a table
print('<table border="0" width="1000px" cellspacing="0" cellpadding="0"><tr><td>');
print('Name:</td>');
print('<td>');
print('Type:</td>');
print('<td>');
print('Size:</td>');
print('<td>');
print('Modified:</td></tr><tr height="20px"><td></tr></td><tr><td>');
$path = "/home/peacher/public_html/directory/";
// Open the folder
$dir_handle = @opendir($path) or die('Unable to open $path');
// Loop through the files
/////this will list directories
while ($file = readdir($dir_handle))
{
if($file == "." || $file == "index.php")////exclude files
continue;
//if the file is a folder
if((mime_content_type($file)) === 'httpd/unix-directory')
{
$folders[] = $file;////puts the folders into an array
}
//...or else it's a file
else
{
$files[] = $file;////puts the files into an array
//$filetype[] = mime_content_type($file); //puts the filetype into another array
//$filesize[] = filesize($file); //puts the size into another array
}
}
// Close
closedir($dir_handle);
sort($folders);
sort($files);
//sort($filetype);
foreach ($folders as $a) ///prints just the name
{
if($a == '..')
{
print('<a href="' . $a . '" target="_self">');
print('Parent Directory');
print('</a>');
print('</td><td>');
print('Parent Directory');// . mime_content_type($a));
print('</td><td>');
print(' - ');
print "</td><td>";
echo date("F d Y H:i:s.", fileatime($a)); ///found at
print('</tr><tr><td>');
}
else
{
print('<a href="' . $a . '" target="_self">');
echo $a;
print('</a>');
print('</td><td>');
print('Directory');// . mime_content_type($a));
print('</td><td>');
print(' - ');
print "</td><td>";
echo date("F d Y H:i:s.", fileatime($a)); ///found at http://us2.php.net/manual/en/function.fileatime.php
print('</tr><tr><td>');
}
}
foreach ($files as $a) ///prints just the name
{
print('<a href="' . $a . '" target="_self">');
echo $a;
print('</a>');
print('</td><td>');
print(' ' . mime_content_type($a));
print('</td><td>');
echo filesize($a) . ' bytes';
print "</td><td>";
echo date("F d Y H:i:s.", fileatime($a));
print('</tr><tr><td>');
}
////finishes the table
print('</td></tr></table>');
?>