Home

viewsrc.php (2.17kB)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<?php

//viewsrc.php

//View the Source of a File

//Works only in the current directory for security reasons.

//By Joey C.

//Things to Do:

//   + Allow for tabs to be shown.  Sort of done.

function fFSize($file) {                                                                  //Formatted File Size

     $size = filesize($file);

     if ($size>=1000000) return round($size/1000000,2)."mB";

     if ($size>=1000) return round($size/1000,2)."kB";

     else return $size." Bytes";

}

if (!$_REQUEST["filename"]) { ?>

<title>View Source</title></head>

<body>No file was requested.  Click <a href="index.php">here</a> to go back.</body>

<?php }

elseif (ereg('\/', $_REQUEST["filename"])==1) { ?>

<title>View Source</title></head>

<body>Working out of this directory is forbidden.  Click <a href="index.php">here</a> to go back.</body>

<?php }

elseif (!file_exists($_REQUEST["filename"])) { ?>

<title>View Source</title></head>

<body>That file does not exist.  Click <a href="index.php">here</a> to go back.</body>

<?php }

else { ?>

<title>View Source: <?php echo $_REQUEST["filename"] ?></title></head>

<body style="font-family:'Courier New', Courier, monospace; font-size: 10pt"><p><a href="index.php">Home</a></p>

<h1 style="font-family:'Times New Roman', Times, serif; margin: 0px; padding: 0px;"><?php echo $_REQUEST["filename"] ?> (<?php echo fFSize($_REQUEST["filename"]) ?>)</h1>

<hr /><p style="text-indent:-2em;padding-left:2em;margin:0px">

<?php

$f = fopen($_REQUEST["filename"], 'r');

$content = fread($f, filesize($_REQUEST["filename"]));

$content = ereg_replace("&", "&amp;", $content);

$content = ereg_replace("<", "&lt;", $content);

$content = ereg_replace(">", "&gt;", $content);

$content = ereg_replace(" ", "&nbsp;", $content);

$content = ereg_replace("\t", "\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $content);

$content = ereg_replace("\n", "</p>\n<p style=\"text-indent:-2em;padding-left:2em;margin:0px\">", $content);

echo $content;

fclose($f);

echo "</p></body>";

}

?>

</html>