LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   writting to file in php (https://www.linuxquestions.org/questions/programming-9/writting-to-file-in-php-278504/)

blitzX 01-16-2005 01:06 PM

writting to file in php
 
Hi, I've been working on this on website for a bit, but theres a problem when I attempt to open a file to append info on it(in PHP). Here's the pseudo code, where i believe the problem is:


Code:

if (!($logging = fopen('./cgi-bin/current.txt', 'a')))
{
        $state = 0;
        $error = '2Unable to open the input file.';
}

yet, if I use this for opening just to read and it works fine:

Code:

if (!($current = fopen('./cgi-bin/users.txt', 'r')))
{
        $state = 0;
        $error = '1Unable to open the input file.';
}

if anyone sees something that I'm missing or knows of any problem like this please reply

-- Ayron

Hko 01-16-2005 01:29 PM

Assuming you run PHP as an apache-module, it will try to open the file as the system-user as used by apache (e.g. user "www" or "www-data", depending on your distribution). This system-user probably does not have write access to the file.

You can find out which system-user apache uses as by creating a file "whoami.php", and access it with a browser. Then make sure the system-user displayed has write-access to your file.

PHP Code:

<?php
    
echo "Apache system user: <b>";
    
system('whoami');
    echo 
"</b><br />";
    echo 
"Apache user is member of these groups: <b>";
    
system('groups');
    echo 
"</b>";
?>


blitzX 01-16-2005 02:57 PM

Thanks, I had completely forgotten about file permissions.


All times are GMT -5. The time now is 03:21 AM.