我使用Ajax在Rss报告中出错:
我使用config.inc.php functions.inc.php作为数据库。即使我赋予了文件和文件夹的权限。
但我没有收到.xml文件中的数据。
请有人帮助我。 如何从.xml文件中接收数据?
这是我的代码:
<?php
session_start();
require_once('includes/config.inc.php');
require_once('includes/functions.inc.php');
$configpath = "surveys/config_" . $_REQUEST['sid'] . ".php";
include_once($configpath); // load survey settings
$rss_template = "<?xml version=\"1.0\" ?>
<rss version=\"2.0\">
<channel>
<title>AskPeople Survey Responses</title>
<description>Live project status (requires login to view results)</description>
<link>[[PROJ-LINK]]</link>
<language>en-gb</language>
<pubDate>[[NOW]]</pubDate>
<lastBuildDate>[[NOW]]</lastBuildDate>
<generator>AskPeople 2.2</generator>
<item>
<title>[[TITLE]]</title>
<description>[[COUNT]] responses received as of [[NOW]].</description>
<link>[[ITEM-LINK]]</link>
</item>
</channel>
</rss>";
if ($_REQUEST['sid']) {
$_SESSION['admin_sid'] = $_REQUEST['sid'];
}
if ($surveysettings['makeRSS'] == "TRUE") {
$now = date("r");
$directory = (substr(dirname($_SERVER['PHP_SELF']),-1) == "/") ? dirname($_SERVER['PHP_SELF']) : dirname($_SERVER['PHP_SELF']) . "/";
$projlink = $protocol . $_SERVER['HTTP_HOST'] . $directory . "survey.php?sid=".$_SESSION['admin_sid'];
$reportlink = $protocol . $_SERVER['HTTP_HOST'] . $directory . "respondentreport.php?sid=".$_SESSION['admin_sid'];
$datafile = "surveys/data_" . $_SESSION['admin_sid'] . ".dat";
$rawdata = loadFile($datafile);
$rawdata_array = explode("\n",$rawdata);
$counter = 0;
for ($r=0;$r<count($rawdata_array);$r++) {
if (strlen($rawdata_array[$r])>0 && $rawdata_array[$r] != "Array") { // some data for this row
$counter++;
}
}
$qid = "surveys/quest_" . $_SESSION['admin_sid'] . ".xml";
$polldata = file_get_contents($qid);
preg_match_all("/<title>(.*?)<\/title>/si",$polldata,$title);
$title = $title[1][0] . ": ". $counter . " responses";
$rss_template = str_replace("[[PROJ-LINK]]",$projlink,$rss_template);
$rss_template = str_replace("[[ITEM-LINK]]",$reportlink,$rss_template);
$rss_template = str_replace("[[NOW]]",$now,$rss_template);
$rss_template = str_replace("[[TITLE]]",$title,$rss_template);
$rss_template = str_replace("[[COUNT]]",$counter,$rss_template);
if ($_REQUEST['file'] == "TRUE") { // for output to a static file
$saved = saveFile($rss_filename,$rss_template);
} else {
echo ($rss_template);
}
}
?>
答案 0 :(得分:0)
将if条件修改为请求:
if ($_REQUEST['file'] == "TRUE") { // for output to a static file
$rss_filename = "rss/rss_".$_SESSION['admin_sid'] . ".xml";
$saved = saveFile($rss_filename,$rss_template);
} else {
echo ($rss_template);
}