LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-16-2005, 01:06 PM   #1
blitzX
Member
 
Registered: Jul 2004
Location: Canada
Distribution: gentoo
Posts: 37

Rep: Reputation: 15
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
 
Old 01-16-2005, 01:29 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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>";
?>

Last edited by Hko; 01-16-2005 at 01:33 PM.
 
Old 01-16-2005, 02:57 PM   #3
blitzX
Member
 
Registered: Jul 2004
Location: Canada
Distribution: gentoo
Posts: 37

Original Poster
Rep: Reputation: 15
Thanks, I had completely forgotten about file permissions.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Writting an OS in C++ makko Programming 2 08-27-2005 07:27 AM
Is a file in writting ? stephnane AIX 3 08-02-2004 11:17 PM
Is a file in writting stephnane Linux - General 2 07-30-2004 09:39 PM
My thread hangs while writting into a file skdevnath Programming 2 03-11-2004 05:13 PM
??.img file without writting itto CD pudhiyavan Linux - General 4 12-04-2003 07:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration