Source Viewers
|
|
|
|
<?
/******************************************
# File: view_source.php
# Description: Script to view code with highligths.
# Link to this file with
# "view_source.php?source=/mypath/myfile.php"
#
# Makes a copy of the php file and names it phps.
# And then redirects the browser to the new phps file.
# phps files are automaticly code highlighted and displayed
# if you are using Apache.
#
# Author: Krister Konst
# krister@krikon.com
******************************************/
function source($source)
{
clearstatcache(); // cache of the filething dele.
if(!file_exists($source)) // Checking for the file $source.
{
return false;
}
// this returns an array of string of wich the last element is the filename.
$path_array= split("/" , $source);
$num = sizeof($path_array); $str = str_replace ("php", "phps", $path_array[$num-1]);
global $target_file
// to make this work you must make the source directory first. $target_file = "./source/" . $str;
copy($source,$target_file);
return true;
}
source($source);
header ("Location: $target_file"); /* Redirect browser
to the newly created phps file/
exit; /* Make sure that code below does
not get executed when we redirect. */
?>
|
|
|
Usage Example
|
<a href="view_source?source=class/person.class.php">source </a>
|
|
|
Rate This Script
|
|
|
|