Fwd: [PHP] php not reading file properly
| From: | sean greenslade | Date: | Wed, 20 Aug 2008 23:31:47 +0000 |
| Subject: | Fwd: [PHP] php not reading file properly | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278435@lists.php.net to get a copy of this message | ||
Thanks for the advice. I changed the perms to 777 and changed the user and
group to apache, but it still won't open.
On Wed, Aug 20, 2008 at 3:35 PM, Robbert van Andel <swimmer1974@gmail.com>wrote:
> Does the user your PHP instance runs as have access to the file? It's
> possible that it runs under a different users depending on if you're running
> the script on the terminal or in a web browser. The function fopen will
> return false if the file fails to open. Find out if $fh is equal to false.
> While you're debugging, you might consider changing the display errors
> setting to see what warning fopen generates if the file fails to open. From
> http://us.php.net/fopen
> Errors/Exceptions
>
> If the open fails, the function an error of level *E_WARNING* is
> generated. You may use
> @<http://us.php.net/manual/en/language.operators.errorcontrol.php>to
> suppress this warning.
>
>
> On Wed, Aug 20, 2008 at 12:15 PM, sean greenslade <zootboysean@gmail.com>wrote:
>
>> I have this snippet of code that is supposed to read the apache access log
>> and display it:
>> <?php
>> $myFile = "/var/log/httpd/access_log";
>> $fh = fopen($myFile, 'r');
>> $theData = fread($fh, filesize($myFile));
>> fclose($fh);
>> echo
>> "This weeks apache log (clears every sunday morning):".
>> substr($theData,0,2000);
>> ?>
>> For some reason, it displays the logs when I run the php file thru
>> terminal:
>> php -f /web/apache.php
>>
>> but not when I access it thru the web. when I browse to it, it just
>> displays
>> the static text ("This weeks apache log (clears every sunday morning):"),
>> not the log text.
>>
>> Very confused,
>> zootboy
>>
>
>
--
Feh.
--
Feh.