PDA

View Full Version : function fopen error



claudio
September 22nd, 2003, 10:53 PM
Im having some problems with a PHP guestbook, something with fopen. When i try to write a message, i get the following error message(see attached file)
This is the php code on post.php:

<?php
// Name and Message required
if (( $name == "") || ( $message == "")) {
print "<p align=center>Preencha todos os campos!<p>";
}
else {
//Get the file
$file_name = "post.xml";
$file_pointer = fopen($file_name, "r+");
$lock = flock($file_pointer, LOCK_EX);
$file_read = fread($file_pointer, filesize($file_name));
$name = strip_tags($name, '');
$message = strip_tags($message, '');
$date = date ("j M Y");
$post = "\n\n<post>\n<p><span class=name>$name</span><span class=date> $date</span><br>$message</p>\n</post>";
//Paste the updated info into the file
$post = stripslashes($post);
fwrite($file_pointer, "$post");
fclose($file_pointer);
print "<head><meta http-equiv=refresh content=0;URL=index.php></head>";
}
?>
Can anyone help me solve this problem? :cyclops:

Jubba
September 22nd, 2003, 11:14 PM
You can't open XML documents for writing like that. Even if the file is CHMODed to 777. I had the same problem at one point.

claudio
September 22nd, 2003, 11:16 PM
What do you suggest me to do Jubba?

[edit] actually, it works on lycos.fr though

Jubba
September 22nd, 2003, 11:18 PM
Does the file have to be XML? Can it just be normal text? Or is this going to be XML based?

edit: Oh really? Well maybe my XML handling isn't up to par. I was having trouble writing to XML documents at one point.

ahmed
September 22nd, 2003, 11:19 PM
try file().. I used that for my xml-newsfeed, it worked fine :)

Jubba
September 22nd, 2003, 11:20 PM
Yeah. If you are just trying to read the XML doc File() should work. But if you want to read it the correct way you would want to use a PHP parser program. And if youw ant to write to it, well I'm not really sure about that one....

claudio
September 22nd, 2003, 11:23 PM
Yes, i need to write to XML... can i use simple txt file?

ahmed
September 22nd, 2003, 11:27 PM
Originally posted by claudio
[edit] actually, it works on lycos.fr though If it works on another server, then it can be that your current server for some reason doesnt allow reading files or something like that :-\

Jubba
September 22nd, 2003, 11:28 PM
Nevermind. Don't listen to me. I was struck by stupidity...

claudio
September 22nd, 2003, 11:33 PM
Arghhhh this is killing me ;(

Jubba
September 22nd, 2003, 11:37 PM
actually... make sure that your XML file is CHMODed to 777 that is probably what is causing the Permissions Error... and then we'll go from there...

claudio
September 23rd, 2003, 12:03 AM
How do i do that Jubba? (sorry, i suck at all this XML, PHP stuff...)

ahmed
September 23rd, 2003, 12:10 AM
http://ca.php.net/chmod

Jubba
September 23rd, 2003, 12:10 AM
CHMODing is setting the permission levels of a file. It allows different groups access to reading/writing/executing your files. Most FTP programs have a CHMOD option.

Google: http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=utf-8&q=chmod+file

Kirupa: http://www.kirupaforum.com/forums/search.php?s=&action=showresults&searchid=159724&sortby=lastpost&sortorder=descending

claudio
September 23rd, 2003, 12:20 AM
Okay where do i put the code? Inside my post.php file?

claudio
September 23rd, 2003, 12:26 AM
Nevermind! I got it working!!
Thanks again ahmed and jubba =)