xml - php write file issue -


i working on php script creates xml file. when run script in browser not written out. when use shell command "php /filelocation" works fine. why this?

<?php include('parse.php');  $test;  $test[0] = "name:actinium"; $test[1] = "symbol:ac"; $test[2] = "atomic number:89"; $test[3] = "atomic weight:[227]";  xml_write($test); ?>  <?php function xml_write($s) {   $temp = explode(":",$s[0]);   $data;   $count = 0;    for($i = 0;$i< sizeof($s);$i++)     {       $temp = explode(":",$s[$i]);       $data[$count] = $temp[1];       $count++;       }   //creates root element   $xml = new domdocument("1.0");   $root = $xml->createelement("table");   $xml->appendchild($root);    //creates name element   $name = $xml->createelement("name");   $nametext = $xml->createtextnode($data[0]);   $name->appendchild($nametext);    //creates symbol element   $symbol = $xml->createelement("symbol");   $symboltext= $xml->createtextnode($data[1]);   $symbol->appendchild($symboltext);    //creates atomic number element   $number = $xml->createelement("number");   $numbertext = $xml->createtextnode($data[2]);   $number->appendchild($numbertext);    //creates atomic mass element   $mass = $xml->createelement("mass");   $masstext = $xml->createtextnode($data[3]);   $mass->appendchild($masstext);    //creates "element" element , binds properties   $ele = $xml->createelement("element");   $ele->appendchild($name);   $ele->appendchild($symbol);   $ele->appendchild($number);   $ele->appendchild($mass);    //attaches ele root   $root->appendchild($ele);    $xml->formatoutput = true;   echo "<xmp>".$xml->savexml()."</xmp>";    $xml->save("/home/anthony/database/table.xml") or die("error"); } 

if aren't setting content-type of 'application/xml' or similar via header(), browser trying render xml html... appear blank page. should able see output if "view-source" browser.

or can set content-type header, , browser display xml.

edit

after re-reading may have mis-interpreted. thought echoing data out. have concur above commenters whomever apache process running not have permission file.

to rule out permissions possibly (depending on host) set path /tmp/table.xml , see if works. assuming permissions issue, apache user (www-data maybe?) need rw permissions on file. if apache create new file, it'll need rw permissions on parent directory well.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -