Re: fopen - append works, write fails (but file is truncated)



On 2007-07-31, frode.nordahl@xxxxxxxxx wrote:
On Jul 28, 7:58 am, Hans Fredrik Nordhaug <han...@xxxxxxxxx> wrote:
On 2007-07-27, Hans Fredrik Nordhaug wrote:



I'm trying to write to a file in the current directory - no remote
files. The subject says it all - I can add that both the directory
and the file is wordwritable. This happens on a (quite good) free
hoster in Norway which doesn't use safe mode, running PHP 5.1.6 as the
PHP info below shows ...

Test it at:
http://home.no.net/moldevbk/fopen-test/?mode=w(write - fails)
http://home.no.net/moldevbk/fopen-test/?mode=a(append - ok)
http://home.no.net/moldevbk/fopen-test/p.php- PHP info
http://home.no.net/moldevbk/fopen-test/fopen-test.phps- source code of test script.

I have searched the web and usenet, but not found this problem
mentioned before. I do realize that I can work around the problem by
truncating the file first and then appending to the empty file - but
that is ugly as ...

Regards, Hans

Just some additional information:

If I delete the file I'm trying to write to, fopen with w mode creates
the file (with owner "nobody") and no errors occurs after that.
Apperently PHP is able to write to the file when it's owned by
"nobody" with permission 644, but not when it's owned by the user
"moldevbk" with permission 666. This is something I would expect to
happen if safe mode was on, but it's not. Append mode works in both
situation. The file is also truncated by the write fopen call in both
situation.

What is going?

Hans

PS! I have contacted the hoster - I'll let you know if they have
some explanation/solution to the issue.

I have investigated this, and there is indeed a problem on our part.
The problem was introduced when we upgraded a web server, and is
caused by incompatibilities with some of the file servers. This does
not affect all of our users.

Thx for the info - I'm glad it wasn't me (or a bug in PHP).

If you want, I can move your account to a different file server. I was
about to do this anyway, but I discovered that you reference absolute
paths in your scripts. I advise you to use relative paths or at least
build the paths from $_ENV['HOME'] or similar.

Feel free to move my account - just send me an e-mail when it's done.
(If the issue is fixed this week without moving, I can wait.)

Hans

PS! I would of course prefer to use $_ENV['HOME'], but $_ENV doesn't
contain HOME because the current user is "nobody" ... The absolute
paths is set in one single file so updating is no problem.
.



Relevant Pages

  • Re: fopen - append works, write fails (but file is truncated)
    ... PHP info below shows ... ... the file (with owner "nobody") and no errors occurs after that. ... happen if safe mode was on, ... Append mode works in both ...
    (comp.lang.php)
  • fopen append works, fopen write fails (but truncates the file)
    ... not created by PHP) - no remote files involved. ... the file (with owner "nobody") and no errors occurs after that. ... "nobody", the webserver user, but not when it's owned by the user ... happen if safe mode was on, ...
    (php.general)
  • [Full-disclosure] copy() Safe Mode Bypass PHP 4.4.2 and 5.1.2
    ... PHP is an HTML-embedded scripting language. ... The PHP safe mode is an attempt to solve the shared-server security problem. ... if (wrapper!= NULL) ...
    (Full-Disclosure)
  • Re: IIS6 and PHP
    ... Enable the PHP scripting language engine under Apache. ... ; every request. ... Maximum number of persistent links. ... Default host for mysql_connect(doesn't apply in safe mode). ...
    (microsoft.public.inetserver.iis)
  • Re: More include issues
    ... I have nobody to turn to except ... Coldfusion, MSSQL, Informix, PHP, oh my! ... creating a test page and play around with it using echo and so on to see ...
    (php.general)