Forum Moderators: coopster
function show_file($file)
{
$code = show_source($file,true);
$kod = "<table cellpadding=\"0\" cellspacing=\"0\">";
$lines = count(file($file));
for ($i=1; $i<=$lines; $i++)
{
$kod .= "<tr><td align=\"center\" width=\"20\" style=\"font: 8pt Tahoma\">";
$kod .= ($i==1)?
"1</td><td valign=\"top\" rowspan=\"".$lines."\">".$code."</td></tr>" :
"$i</td></tr>";
}
$kod .= "</table>";
echo $kod;
return $kod;
}
Are the line numbers displayed? I assume that you must be getting a line count, otherwise you would get no rows, empty or otherwise.
So I have to assume that you are able to read the file via file() but your linux machine has safe mode in effect and this is causing problems with show_source.
[php.net...]
Tom
If that's possible, you can write the contents out without syntax highlighting. I'm not sure, but it's possible that if you write the file from PHP, the owner ('nobody', ie php) will be the same as the user trying to access the file via show_source (again the php process) and you might be able to access it.
I don't know that much about safe mode to be honest though.
Tom
According to the manual, when safe_mode is on, WRT the show_source function
Checks whether the files or directories you are about to operate on have the same UID (owner) as the script that is being executed.
So I would assume that if you write your source using PHP and do so within a directory where you have full permissions, you should be able to use show_source on it. It seems odd that it would be this easy to get around, so I'm wondering whether there's a flaw in my reasoning. Anyway, what I would try is this.
- take the code in $lines and write it out to a file (e.g. 'code-holder.php').
- the owner of the file should now be PHP, which should be able to read it
- read it in with show_source.
I'll be sort of flabbergasted if that works, but give it a whirl.
Tom