Re: using fopen() in write mode is failing



On Sat, 31 May 2008 00:54:42 +0200, <cscorley@xxxxxxxxx> wrote:

On May 30, 4:26 pm, Jerry Stuckle <jstuck...@xxxxxxxxxxxxx> wrote:
cscor...@xxxxxxxxx wrote:
> On May 30, 3:13 pm, Gordon <gordon.mc...@xxxxxxxxxxxx> wrote:
>> On May 30, 9:08 pm, cscor...@xxxxxxxxx wrote:

>>> For some reason, I cannot use fopen() on the file in write mode. The
>>> file "time" is in the same directory as the .php file, with
>>> permissions set to 0766.
>>> PHP Version 5.2.5
>>> Apache/2.2.8
>>> code snip in question:
>>> $file = "time";
>>> function updateParseTime($name){
>>> global $file;
>>> if (file_exists($name) && file_exists($file)) {
>>> if(($fp = fopen($file,"wb"))){
>>> $lastmod = filemtime($name);
>>> if(!(fwrite($fp, $lastmod))){
>>> echo "cannot update time";
>>> }
>>> }
>>> else{
>>> echo "$file cannot be opened. \n";
>>> }
>>> }
>>> else{
>>> echo "$name or $file not found.";
>>> }
>>> }
>>> on the 4th line it fails the if check ($fp = fopen...) and just
>>> outputs "$file cannot be opened"
>>> Am I missing something?
>> Is error reporting on? If it is then PHP will echo out its own error
>> message in addition to yours. Did you originally create the file
>> you're trying to write to or was it created via a PHP script? If the
>> former is the case then it will have you as the owner. PHP runs as the
>> webserver's user (something like www or apache or nobody, assuming
>> you're using PHP in a webserver environment). This will mean a
>> permission denied error occurs when you try to open the file. Try
>> setting the file to 666 chmod, or chown it to the Apache process's
>> user.

> I 'touch'ed the file on the server itself, so yes its owned by my
> user. I've attempted to chown+chgrp the file to apache's, but it
> doesn't help at all. The file is already chmod'ed to 0766.

> After turning on error reporting, it outputs this:

> "Warning: fopen(time) [function.fopen]: failed to open stream:
> Permission denied in /var/www/html/xmlparser.php on line 53"

> with line 53 being the $fp = fopen().. line.

What's in $file at the time you try to call fopen()? And why do you
have the file set as executable by the owner?

The file named "time" is (sans quotations of course) in $file. The
time file itself is blank.

It was just set for rwx when I touched the file, so i just kept it and
added write permissions to the file for other users. I've changed it
to 0666 but it doesn't seem to affect anything.

What is your getcwd()? Is it what you expect / the directory 'time' should be in?
--
Rik Wasmus
....spamrun finished
.



Relevant Pages

  • Re: write with cURL
    ... offers PHP, if they don't allow PHP to open and write ... Check the permissions on the directory the file is ... such as chmod 0666 test.txt ... their server configuration is, too, though. ...
    (alt.php)
  • Re: write with cURL
    ... offers PHP, if they don't allow PHP to open and write ... Check the permissions on the directory the file is ... such as chmod 0666 test.txt ... their server configuration is, too, though. ...
    (alt.php)
  • Re: write with cURL
    ... execute permissions. ... This is assuming that the PHP script runs ... of potential security risks from other users on the same server. ... Apache as the global web server user and thus needs world write ...
    (alt.php)
  • Re: [PHP] File Upload Security and chmod
    ... It was never a question of speed for me -- it was a question of being able to change file permissions from within a php script so that I could create and write files safely. ... I am *not* able to use chmodwithin a php script at all regardless of what permissions the file and parent folder have -- even when both are set to 0777. ... So, if you can chmodand mkdirfrom within your php script without establishing an ftp connection, then more power to you, because I can't. ...
    (php.general)
  • Re: write with cURL
    ... PHP, if they don't allow PHP to open and write to files. ... Check the permissions on the directory the file is to ... chmod 0777 test.txt and see if you can write to it then. ... their server configuration is, too, though. ...
    (alt.php)