www.webdeveloper.com
Results 1 to 9 of 9

Thread: fopen problem

  1. #1
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    7

    fopen problem

    Hi,
    i have installed a php-blog program (xbloglite) on my server, but when i login as a administratot and want to post a message the following errors appear:

    Warning: fopen(/usr/local/psa/home/vhosts/sportklimtraining.nl/httpdocs/xbloglite/archives/00001.php): failed to open stream: Permission denied in /usr/local/psa/home/vhosts/sportklimtraining.nl/httpdocs/xbloglite/addblog.php on line 129

    Warning: fwrite(): supplied argument is not a valid stream resource in /usr/local/psa/home/vhosts/sportklimtraining.nl/httpdocs/xbloglite/addblog.php on line 131

    Warning: fclose(): supplied argument is not a valid stream resource in /usr/local/psa/home/vhosts/sportklimtraining.nl/httpdocs/xbloglite/addblog.php on line 133

    Warning: Cannot modify header information - headers already sent by (output started at /usr/local/psa/home/vhosts/sportklimtraining.nl/httpdocs/xbloglite/addblog.php:129) in /usr/local/psa/home/vhosts/sportklimtraining.nl/httpdocs/xbloglite/addblog.php on line 141

    The code of addblog it refers to is:
    $fp = fopen("inc/saved.txt", "wb");
    @flock($fp, LOCK_EX);
    fwrite($fp, $saved);
    @flock($fp, LOCK_UN);
    fclose($fp);

    I already checked the permissions on saved/txt, and think they are ok (644). However, when i change this permission to 777 I get the following error:
    Warning: fopen(/usr/local/psa/home/vhosts/sportklimtraining.nl/httpdocs/xbloglite/archives/00001.php): failed to open stream: Permission denied in /usr/local/psa/home/vhosts/sportklimtraining.nl/httpdocs/xbloglite/addblog.php on line 129
    etc etc.
    Of course I can change the permissions of that file to 777 too, but isn't that a safety problem?? These permissions are supposed to ONLY let ME write to the files as a administrator, right?

    I'm just a beginner with PHP and understand I have to do a lot of research to learn it, but has anyone some suggestions for the problem above??

    Thanks,
    Matthijs

  2. #2
    Join Date
    Mar 2004
    Location
    London, UK
    Posts
    342
    First of all check your paths in the settings.php or config.php

    Whenever I've run into this sort of trouble, it's been largely due to incorrect pathing.

    Of course, there are other times when the problem could be due to fopen() being disabled. But this, I'm sure, you've probably ascertained through the phpinfo()

  3. #3
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    7
    thanks for the reply.
    I just looked at my phpinfo, but couldn't find something with fopen. Where do I have to search?? And if fopen isn't there, does that maen this function has to be installed on the server?

    thanks,
    Matthijs.

  4. #4
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    7
    I just found out in the phpinfo file the following:

    allow_url_fopen On

    Is that what you meant?
    Matthijs

  5. #5
    Join Date
    Mar 2004
    Location
    London, UK
    Posts
    342
    Yes, that's what I meant. Generally if allow_url_fopen = "1" (or = "on") then fopen should work, unless the web host has blocked some relevant ports.

    So, maybe, let's see if you are able to read the file. If you are, then we know fopen() is okay. In which case the problem should lie with the 'write' permissions.

    ...something like
    PHP Code:
     $fp fopen("inc/saved.txt""r");
    while(!
    feof($fp))
    {
        
    $data .= fgets($fp4096);
    }

    echo 
    $data

  6. #6
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    7
    Thanx for the advise!
    I uploaded the following file with the script you suggested to my server (as test.php), in the same directory as where inc/ is:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-translitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title> First PHP script</title>
    </head>
    <body>
    <?php

    $fp = fopen("inc/saved.txt", "r");
    while(!feof($fp))
    {
    $data .= fgets($fp, 4096);
    }

    echo $data;

    ?>
    </body>
    </html>

    However when I try to visit the page test.php nothing appears on the screen of my browser.
    I'm sure PHP works because the following test2.php file returned a nice "hello world":
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-translitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title> First PHP script</title>
    </head>
    <body>
    <?php
    print ("Hello, world!");
    ?>
    </body>
    </html>

    So what might be the problem???
    1) saved.txt is in the right directory (in/saved.txt);
    2) saved.txt has the right permissions (777);

    Could the problem be what is actually in the saved.txt file??
    I'll keep on trying stuff, but if anyone has a suggestion, thanks a lot!

    Matthijs.

  7. #7
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    try this instead:
    Code:
    <?php
    $file = 'inc/saved.txt';
    $fp = fopen($file, 'rb');
    $data = fread($fp, filesize($file));
    fclose($fp);
    ?>

  8. #8
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    7
    I tried your file but ther's still nothing appearing.
    I uploaded:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-translitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title> First PHP script</title>
    </head>
    <body>
    <?php
    $file = 'inc/saved.txt';
    $fp = fopen($file, 'rb');
    $data = fread($fp, filesize($file));
    fclose($fp);
    ?>
    <p> hello</p>
    </body>
    </html>
    to the server, in the same dir as inc/
    Then, when I browse to this file (test.php): nothing! I'm sure the file (test3.php) is there because I see 'hello' on the screen. Only the php is not reading the file saved.txt.

    I tried setting the permissions of saved text to 777, I tried putting some text in saved.txt, i tried putting no text in the file...
    Maybe something else: what should I put in saved.txt for the php script to read something? Plain text? HTML? Maybe if I put something specific in it I can test it.

    Thanx again for all the help,
    Matthijs, Holland.

  9. #9
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    7

    Talking

    Ok there is some progression!
    I got the error message:
    Warning: fopen(/usr/local/psa/home/vhosts/sportklimtraining.nl/httpdocs/xbloglite/archives/00001.php): failed to open stream: Permission denied in /usr/local/psa/home/vhosts/sportklimtraining.nl/httpdocs/xbloglite/addblog.php on line 129


    I changed he permissions on the dir archives to 777 and now it works. I can post a message on the blog.
    However, by setting the permissions of that file on 777, do I create a security problem?? because it was 644.

    If someone can answer this question, thanks a lot,
    Matthijs.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles