/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@solavarMay 20.2004 — 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()
Copy linkTweet thisAlerts:
@matthijsklimmerauthorMay 20.2004 — 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.
Copy linkTweet thisAlerts:
@matthijsklimmerauthorMay 20.2004 — I just found out in the phpinfo file the following:

allow_url_fopen On

Is that what you meant?

Matthijs
Copy linkTweet thisAlerts:
@solavarMay 20.2004 — 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
[code=php]
$fp = fopen("inc/saved.txt", "r");
while(!feof($fp))
{
$data .= fgets($fp, 4096);
}

echo $data;

[/code]
Copy linkTweet thisAlerts:
@matthijsklimmerauthorMay 20.2004 — 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.
Copy linkTweet thisAlerts:
@ShrineDesignsMay 20.2004 — try this instead:&lt;?php
$file = 'inc/saved.txt';
$fp = fopen($file, 'rb');
$data = fread($fp, filesize($file));
fclose($fp);
?&gt;
Copy linkTweet thisAlerts:
@matthijsklimmerauthorMay 20.2004 — 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.
Copy linkTweet thisAlerts:
@matthijsklimmerauthorMay 20.2004 — 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.
×

Success!

Help @matthijsklimmer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...