Forum Moderators: coopster

Message Too Old, No Replies

function not working under linux

but it does under windows

         

sebbothebutcher

4:28 pm on Aug 6, 2004 (gmt 0)

10+ Year Member



hi i've got a problem!
my own computer is running under windows, and i've created a function which looks like this:

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;
}

it works perfectly under windows, but on my linux server the script outputs the lines of the file, but every line is empty... does anybody have an idea, why this keeps happening?
thanks in advance

timster

7:23 pm on Aug 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could it be a line endings issue? If you have a Windows file, with its CRLF line endings, on a Linux machine (which uses just LF) the carriage return may be confusing things.

sebbothebutcher

8:31 pm on Aug 6, 2004 (gmt 0)

10+ Year Member



well... i also thought about that, but since the files were written on my computer (windows) the line endings should be CRLF, and not LF... any other ideas?

ergophobe

8:55 pm on Aug 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Define empty? Do you mean an empty table row? So the html for the table is there, but there no actual data displayed?

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

sebbothebutcher

5:29 pm on Aug 7, 2004 (gmt 0)

10+ Year Member



the line numbers are displayed, but the filed where the source should appear is empty! also, the line numbers are being displayed correctly, so there seems to be no problem with acutally reading the file!

ergophobe

6:08 pm on Aug 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So then my hypothesis is probably correct. It's a safe_mode issue.

sebbothebutcher

8:49 pm on Aug 7, 2004 (gmt 0)

10+ Year Member



is there any way to work around it? i can't change any configuration of this server since it doesn't belong to me...! do you have any ideas?

ergophobe

9:23 pm on Aug 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



First, just verify that in fact you are able to read your file into an array using file().

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

sebbothebutcher

10:02 pm on Aug 7, 2004 (gmt 0)

10+ Year Member



i've tried this simple program

<?php
$lines = file("test.txt");
for($i = 0; $lines[$i]; $i++)
echo "<b>$i</b>: $lines[$i]<br>\n";
?>

and it worked. so file() seems to be working...
any suggestions how to continue?

ergophobe

11:05 pm on Aug 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As I say, I've never dealt much with safe_mode and so I'm just grasping at straws here.

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

sebbothebutcher

11:23 pm on Aug 7, 2004 (gmt 0)

10+ Year Member



okay! i'll try that one... i'll let you know when it worked out!

sebbothebutcher

1:01 am on Aug 8, 2004 (gmt 0)

10+ Year Member



i've tried it now with this function

function copyAndShow($file)
{
copy($file,"codeholder.php");
show_file("codeholder.php");
unlink("codeholder.php");
}

but the output was still the same as before (just linenumbers, no file contents)!
anything else i could do?

ergophobe

1:37 am on Aug 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



But codeholder.php does have the code in it?

I guess you just need to output the code without highlighting.

sebbothebutcher

12:22 pm on Aug 8, 2004 (gmt 0)

10+ Year Member



yes... codeholder.php contains the file contents... well... maybe i'll have to write a syntax highlight function myself... :-/
but thanks a lot for your help!