Jump to content



Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
Photo
- - - - -

Having Problems With Saving Xml File


10 replies to this topic

#1 demolaynyc

demolaynyc

    Premium Member

  • Members
  • 330 posts

Posted 14 October 2006 - 03:13 PM

Hi, I'm trying to make a guestbook using PHP and XML but I can't seem to save my XML when i try to save it. I use the XML.send() function to send the raw_post_data to be saved onto my guestbook.xml file. Somehow, it doesn't seem to save it. Can anyone help me?

Here's the php code
<?php  
$filename = "guestbook.xml";
$raw_xml = file_get_contents("php://input");

print $raw_xml;

$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);
fclose($fp);
?>

Is there anything wrong with this file that I don't see?
Can anyone give me an alternative php script?

#2 vujsa

vujsa

    Absolute Newbie

  • [MODERATOR]
  • 888 posts
  • Gender:Male
  • Location:Indianapolis, Indiana, USA (Midwest)
  • myCENTs:35.43

Posted 14 October 2006 - 07:24 PM

The only thing I can imagine that might be wrong is you file or directory permissions.

If you don't set the directory and the file you want to save to write ALL, the file won't save and I don't think PHP will return an error. chmod to 666 for the file and 777 for the directory. That should solve the issue. If you already have your permissions set correctly, then I'll have to further evaluate the problem.

vujsa

#3 demolaynyc

demolaynyc

    Premium Member

  • Members
  • 330 posts

Posted 14 October 2006 - 11:16 PM

how would i fix that chmod in astahost? Sorry but I don't know how to configure these settings.

#4 vujsa

vujsa

    Absolute Newbie

  • [MODERATOR]
  • 888 posts
  • Gender:Male
  • Location:Indianapolis, Indiana, USA (Midwest)
  • myCENTs:35.43

Posted 14 October 2006 - 11:28 PM

Well, in your cPanel, do as follows:
Goto: cPanel > File Manager > Click on Filename > Change Permissions > Read All, Write All.

Do the same for your directory except click on the directory name instead of filename and it should be execute all as well.

Be sure to click the name and not the icon. The icon takes you to that directory while the name gives you the options for that item in the upper right side of the window.

For files, 666 is read all and write all.
For directories, 777 read all, write all, and execute all.
[hr=0] [/hr]
With your FTP manager, the process is probably much different.

Ususally, your local files are on the left side and the remote files on the right side. RIGHT Click on the remote file or directory name to display your options. Select change permissions or CHMOD! Use the same setting as above.

Hope this helps.

vujsa

#5 demolaynyc

demolaynyc

    Premium Member

  • Members
  • 330 posts

Posted 14 October 2006 - 11:31 PM

Ok, I changed the permissions, but they're still the same

#6 vujsa

vujsa

    Absolute Newbie

  • [MODERATOR]
  • 888 posts
  • Gender:Male
  • Location:Indianapolis, Indiana, USA (Midwest)
  • myCENTs:35.43

Posted 15 October 2006 - 12:22 AM

So I just tried you script on my home system and my hosting account and everything worked fine with the sample data I used which was just a username.

Are you looking in the right place for the saved file? It will be in the exact same directory as the script that saves it. It will not be in the root directory or any other place. So if your script is /scripts/save_guestbook.php then your XML file will be /scripts/guestbook.xml also!

Other than this, I have no idea what might be wrong! The script works unless there is somethin in your XML file causing problems.

Try changing $raw_xml = file_get_contents("php://input"); to $raw_xml = "Test Data";

Hope this helps.

vujsa

#7 demolaynyc

demolaynyc

    Premium Member

  • Members
  • 330 posts

Posted 15 October 2006 - 12:33 AM

Yep, they're both in the same place. Hold on, I'll give you the url and you test it for yourself. I post a comment and it loads into the output TXT however when I go to a different page, it disappears.

Here's the AS code, please take a look at it and look for any errors.

var inputXML = new XML();
inputXML.ignoreWhite = true;
inputXML.contentType = "text/xml";
inputXML.load("guestbook.xml");

var outputXML = new XML();
outputXML.ignoreWhite = true;
outputXML.onLoad = function () {
	gb_output ="";
	var postElement = inputXML.firstChild.childNodes;
	for (var i=0; i<postElement.length; i++) {
		gb_output += "<b>Name: </b>"+postElement[i].attributes.name+"<br>";
		gb_output += "<b>Date: </b>"+postElement[i].attributes.date+"<br>";
		gb_output += "<b>Message: </b><br>"+postElement[i].attributes.message+"<br><br>";
		gb_output += "__________________<br>";
	}
}
outputXML.load("guestbook.xml");

btn_submit.onRelease = function () {
	var date = new Date();
	var cDate = (date.getMonth()+1)+"-"+(date.getDate())+"-"+(date.getFullYear());
	
	var node = inputXML.createElement("post");
	node.attributes.message = form.gb_message.text;
	node.attributes.date = cDate;
	node.attributes.email = form.gb_email.text;
	node.attributes.name = form.gb_name.text;
	
	inputXML.firstChild.insertBefore(node, inputXML.firstChild.firstChild);
	inputXML.sendAndLoad("GBaddPost.php", outputXML);
	popup.gotoAndPlay(2);
}

	


http://demolaynyc.as...oject1/index_v4[8].swf --go to Fan ZOne page

<?xml version="1.0"?><guestbook><post name="Albert Villaroman" email="masugidsk8r@yahoo.com" date="10-14-2006" message="Yo man this is just a text but I think this test will work. I sure hope so man, I really do so please load and send it back to this movie please? THank you." /><post name="unnamed 1" email="nomail@domain.com" date="10-11-06" message="hello" /></guestbook>

Edited by demolaynyc, 15 October 2006 - 12:46 AM.


#8 vujsa

vujsa

    Absolute Newbie

  • [MODERATOR]
  • 888 posts
  • Gender:Male
  • Location:Indianapolis, Indiana, USA (Midwest)
  • myCENTs:35.43

Posted 15 October 2006 - 02:36 AM

Oh man, I can help all day with the PHP but the AS is not my area of knowledge. Never used it before. If you problem is on the AS side of the system, I won't be able to help. I'm really sorry.

vujsa

#9 demolaynyc

demolaynyc

    Premium Member

  • Members
  • 330 posts

Posted 16 October 2006 - 05:29 PM

Somehow, eventually the comment posted is saved to the guestbook.xml after like hours of the time of post. So, the codes do work, but it doesn't save right away, it takes the next day for the update to show up. So what may be the problem?

#10 vujsa

vujsa

    Absolute Newbie

  • [MODERATOR]
  • 888 posts
  • Gender:Male
  • Location:Indianapolis, Indiana, USA (Midwest)
  • myCENTs:35.43

Posted 16 October 2006 - 08:31 PM

I bet it is your browser cache. Try saving something then clear your cache to see if it is there afterwards. If that is the problem, I'm not sure how to fix that without setting no cache on the entire website.

Since this isn't reallt my area, I can't help too much but I know that PHP isn't waiting to save your file. The process is real time. There isn't any file upload buffer on the server for PHP to use other than the "temp" folder but that clears out when the script moves on to the next task.

vujsa

#11 demolaynyc

demolaynyc

    Premium Member

  • Members
  • 330 posts

Posted 20 October 2006 - 05:20 PM

Alright, now I have no problems in Astahost but when I upload it to Hostway.com The PHP script doesnt work in that host site. I used php://input and $HTTP_POST_DATA.

The same flash works here in astahost but the hostway.com uses only 4.0 version. Does that cause the problem. If so, what code could I use to be able to save the guestbook.xml file?



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users