dongyin8009 2015-02-23 21:59
浏览 20

XML文件不通过托管服务器上的PHP脚本更新

Content not updating in xml file on hosting server.

<?php
 $xml = new DOMDocument('1.0', 'utf-8');
 $xml->formatOutput = true;
 $xml->preserveWhiteSpace = false;
 $xml->load('rates.xml');

 //Get item Element
 $element = $xml->getElementsByTagName('rates')->item(0);

 //Load child elements
 $name = $element->getElementsByTagName('gold')->item(0);
 $comment = $element->getElementsByTagName('silver')->item(0);

 //Replace old elements with new
 $element->replaceChild($name, $name);
 $element->replaceChild($comment, $comment);
 ?>
<body><hr>
 <form method="POST" action='' autocomplete="off">
     Enter Gold Rate (Rs/10g) : <input required type="text" value="<?php echo $name->nodeValue  ?>" name="gold-rate" pattern="^[0-9]{5}$" placeholder="for 10g"></br></br>
Enter Silver Rate (Rs/kg) :  <input required type="text" value="<?php echo $comment->nodeValue  ?>"  name="silver-rate" pattern="^[0-9]{5}$" placeholder="for 10g"/></br></br>
 <input name="submit" type="submit" />

 </form><hr>
</body>
 <?php


 if (isset($_POST['submit'])) 
 { 
$name->nodeValue = $_POST['gold-rate'];
$comment->nodeValue = $_POST['silver-rate'];
htmlentities($xml->save('sample.xml'));

 }


 ?>

Above code is about form submission of two values i am trying to save in XML and then display it elsewhere. On local-host it got success, but on server this php script is unable to change the data of my XML file. Permissions for the folder i set is 755 and all files at 644. Tried changing the permissions and ended up with 500 internal error. As this looks server-side security matter, i have no clue where to end up looking for solution. Server is running on PHP 5.6, tried solutions from other users but nothing fruitful. Should i have to change something in php or do i have to contact my hosting provider.

  • 写回答

1条回答 默认 最新

  • doulun5683 2015-02-23 23:01
    关注

    The HTTP server normally runs with an user without permission to modify files on the server. Most web applications store any data which can be modified in a database.

    If you want to have a file or directory writable by the web server, you can try:

    • make the parent directory writable to the web server.
    • run a small php script which creates the file or directory
    • restore the original permission on the directory

    And after that you can write to the file from your original php file.

    I guess you get a 500 error if either your php script or its parent directory is world writable. Depending on your hosting provider, it may work if you create a separate directory for any files written to by the server.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测