john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

php index 2009 03 22

<html>

<?php
//index pages Search Engine Optimised, title, etc. will be the current dir
//"bread crumb" listing for site navigation at the top
//last updated 26mar09 by johnpfeiffer

$servername = $_SERVER['SERVER_NAME'];
$page = $_SERVER['PHP_SELF'];             //get the url of the resource (webpage)
$querystring = $_SERVER['QUERY_STRING'];
$title = explode("/", $page);             //break the url into pieces
$currentfile = end($title);               //the name of the current file (last piece)
$directory = prev($title);                //find the current directory
$arr = explode("-", $directory);         //break the directory name down into words
$seocontent = implode(" ", $arr);        //create a string from words (with spaces)

echo "<head>\n";
echo "<title>$seocontent</title>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>";
echo "<meta name=\"description\" content=\"$seocontent\"/>\n";
echo "<meta name=\"keywords\" content=\"$seocontent\"/>\n";
echo "</head>\n";
echo "<body>\n";

print_r($title);
echo "\n";

foreach ($title as $breadcrumbs)
{  if( $breadcrumbs != $currentfile )       //don't print the current file
   {   echo "<a href=\"http://$servername/$breadcrumbs\">$breadcrumbs</a>/\n";
   }
}

echo "<h3>$seocontent</h3>\n";

//$d = dir( getcwd() );
//echo "Handle: " . $d->handle . ", Path (not necessarily accurate): " . $d->path . "\n<br>";
//echo "<title>" . $d->path . "/</title>";
//$d->close();

$dh = opendir( getcwd() );  //get current working directory

while (false !== ($file = readdir($dh)))
{
    if( $file != "." && $file != ".." ) //don't test the root directories
    {
        if( is_file($file) )
        {   $filelist[] = $file;    }
        else
        {   $dirlist[] = $file;     }
    }
}

echo "<table>\n";                       //a table for our dir/file names & sizes

if( $dirlist[0] != NULL )               //maybe there are no directories
{
    sort($dirlist);
    foreach ($dirlist as $value)
    {
        echo "<tr>";
        echo "<td><a href=\"" . $value . "\">" . $value . "</a></td>\n";
        echo "<td>&nbsp;</td>";
        echo "<td>" . date("dMy H:s T", filemtime($value)) . "</td>";
        echo "</tr>\n";
    }
}

sort($filelist);
foreach ($filelist as $value)
{
    echo "<tr>";
    echo "<td><a href=\"" . $value . "\">" . $value . "</a></td>";
    echo "<td>&nbsp;</td>";
    echo "<td>" . filesize($value) . " bytes</td>";
    echo "<td>&nbsp;</td>";
    echo "<td>" . date("dMy H:s T", filemtime($value)) . "</td>";
    echo "</tr>\n";
}
echo "</table>";

echo "\n<br>";
echo "\n" . getcwd() . " contains " . sizeof($filelist) . " files and " .
    sizeof($dirlist) . " directories\n<br>\n";
    closedir($dh);
?>
<br>index.php modified 26mar09 by john pfeiffer

</body>
</html>

  • « drupal contact form
  • windows xp boot multiple operating systems boot ini »

Published

Feb 15, 2010

Category

php

~268 words

Tags

  • file listing 1
  • index 8
  • php 82