开发者

XML+PHP+DOM "write on xml" Why it's not working in a specific server?

I just can't figure why it's not working on my server...

I hope someone will help me please :( I will try to make it as clear as possible..

I have made a good working script in PHP+XML+DOM that write into xml and display it with an xml reader. and it's working good on some free hosting

now..I copy the files into my server and it's not working. I can see the xml with the reader.. but i can't write on the xml file.

Those are the very same files in both places..

Can you help me please?

BTW:Feel free to add any data to the xml..it's only for the example..

Sites:

Free Hosting: http://ofear.onlinewebshop.net/xml/XmlReader.php

My Server: http://apps.sce.ac.il/testxml/asce/xml/XmlReader.php

PhpInfo:

Free Hosting: http://ofear.onlinewebshop.net/xml/phpinfo.php

My Server: http://apps.sce.ac.il/testxml/asce/xml/phpinfo.php

Files:

events.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<events>
    <record>
        <event>1</event>
        <eventDate>2</eventDate>
        <desc>3</desc>
    </record>
</events>

parser.php: (I added echos for debugging)

<?php

header("Content-type: text/html; charset=utf-8");
echo("set header<br/>");

$record = array(
 'event' => $_POST['event'],
    'eventDate' => $_POST['eventDate'],
    'desc' => $_POST['desc'],
);
echo("set array<br/>");

$doc = new DOMDocument();
$doc->load( 'events.xml' );
echo("make new dom and load the xml<br/>");

$doc->formatOutput = true;
echo("formatin output<br/>");

$r = $doc->getElementsByTagName("events")->item(0);
echo("get element events<br/>");

$b = $doc->createElement("record");
echo("create element record<br/>");

$event = $doc->createElement("event");
echo("create element event<br/>");

$event->appendChild(
    $doc->createTextNode( $record["event"] )
);
echo("create TextNode event<br/>");

$b->appendChild( $event );
echo("appendChild event<br/>");

$e开发者_运维知识库ventDate = $doc->createElement("eventDate");
$eventDate->appendChild(
    $doc->createTextNode( $record["eventDate"] )
);
echo("create TextNode eventDate<br/>");

$b->appendChild( $eventDate );
echo("appendChild eventDate<br/>");

$desc = $doc->createElement("desc");
$desc->appendChild(
    $doc->createTextNode( $record["desc"] )
);
echo("create TextNode desc<br/>");

$b->appendChild( $desc );
echo("appendChild desc<br/>");

$r->insertBefore( $b,$r->firstChild );
echo("insertBefore firstChild<br/>");

$doc->save("events.xml");
echo("Saving events.xml<br/>");

echo("<br/><br/><a href='XmlReader.php'>Go Back to XML Reader</a><br/>");
   // header("Location: {$_SERVER['HTTP_REFERER']}");    
?>

XmlReader.php: (only the php script)

<?php
$doc = new DOMDocument();
$doc->load( 'events.xml' );

$events = $doc->getElementsByTagName( "record" );
foreach( $events as $record )
{
  $events = $record->getElementsByTagName( "event" );
  $event = $events->item(0)->nodeValue;

  $eventDates= $record->getElementsByTagName( "eventDate" );
  $eventDate= $eventDates->item(0)->nodeValue;

  $descs = $record->getElementsByTagName( "desc" );
  $desc = $descs->item(0)->nodeValue;

  echo "<tr><td>$event</td><td>$eventDate</td><td>$desc</td></tr>";
  }
?>


It was a problem with the file permission.

I gave a 755 permission to all files and it resolved it.

Thanks to rik with his suggestion.

Please add error_reporting(E_ALL), ini_set('display_errors', 1); on top of parser.php, run the script and post the output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜