解
<?php
include("authenticate.php");
$user = $_SESSION['UserName'];
$initialdata = $result = mysql_query("SELECT * FROM ccregisterfeed WHERE username = '$user'");
while($row = mysql_fetch_assoc($initialdata)){
$filename = $row["feedlink"];
// var_dump ($filename);
}
$initdata = mysql_fetch_assoc($initialdata);
$result = mysql_query("SELECT * FROM ccshowcontent JOIN ccaudio ON ccshowcontent.id = ccaudio.id WHERE ccshowcontent.username = '$user' ORDER BY ccshowcontent.id DESC")
or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$items[] = $row;
}
$rss = createXML($items,$initdata);
//echo "feed updated!";
$filename = ($filename);
file_put_contents($filename,$rss);
header("Location: ccupload.php?message=".urlencode("Show saved and feed updated"));
?>
全文
<?php
include("authenticate.php");
$user = $_SESSION['UserName'];
$initialdata = $result = mysql_query("SELECT * FROM ccregisterfeed WHERE username = '$user'");
$initdata = mysql_fetch_assoc($initialdata);
$result = mysql_query("SELECT * FROM ccshowcontent JOIN ccaudio ON ccshowcontent.id = ccaudio.id WHERE ccshowcontent.username = '$user' ORDER BY ccshowcontent.id DESC")
or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$items[] = $row;
}
function createXML($items,$data){
$xml = "<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
<channel>
<atom:link href='".$data['feedlink']."'
rel='self' type='application/rss+xml' />
<title>".$data['feedtitle']."</title>
<link>".$data['websitelink']."</link>
<category domain=''>".$data['category']."</category>
<copyright>".$data['copyright']."</copyright>
<pubDate>".date("D, d M Y H:i:s O", strtotime($data['pubdate']))."</pubDate>
<language>en-us</language>
<description>".$data['feeddescription']."</description>
<image>
<title>".$data['feedtitle']."</title>
<link>".$data['websitelink']."</link>
<url>".$data['imagelink']."</url>
<description>".$data['imagetitle']."</description>
</image>";
$audiodir = "http://thetradingcardgenerator.com/MP3/";
foreach($items as $key => $item){
$path = $audiodir.$item['path'];
$pdate = strtotime($item['pubdate']);
$date = date("D, d M Y H:i:s O", $pdate);
$xml .="
<item>
<title>".$item['title']."</title>
<link>".$path."</link>
<guid>".$path."</guid>
<pubDate>".$date."</pubDate>
<description><![CDATA[".$item['description']."]]></description>
</item>";
}
$xml .="
</channel>
</rss>";
return $xml;
}
$rss = createXML($items,$initdata);
//echo "feed updated!";
$filename = '$feedlink' . ".xml";
file_put_contents($filename,$rss);
header("Location: ccupload.php?message=".urlencode("Show saved and feed updated"));
?>
首次入场
我编写了一个脚本,用于根据表格中输入的数据生成rss Feed。我想从表中的字段生成文件名,我创建如下:
$path = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$feedtitle = str_replace(" ", "", $feedtitle);
$feedtitle = str_replace("_", "", $feedtitle);
$feedtitle = str_replace("-", "", $feedtitle);
$feedtitle = strtolower($feedtitle);
$path = substr($path, 0, strrpos($path, "/"));
$feedlink = "$feedtitle" . '.xml';
因此,如果$ feedtitle是Last Nights Television,$ feedlink的值将是
lastnightstelevision.xml
我通过指定文件名测试了脚本并且它可以工作,从表中提取数据并创建一个feed。这是脚本的最后一部分:
$rss = createXML($items,$initdata);
$filename = 'myfeed.xml';
file_put_contents($filename,$rss);
header("Location: uploadcontent.php?message=".urlencode("Show saved and feed updated"));
?>
在我的服务器上创建了一个名称myfeed.xml。
但是我希望Feed的文件名是$ feedlink的值。我知道这可能是基本的,但我无法弄清楚如何去做。
我试过了:
$filename = ".$feedlink";
$filename = ".$feedlink[feedlink]";
以及许多其他组合。
答案 0 :(得分:0)
如果您尝试从RSS获取该文件名,请尝试使用
$attribute = $rss->channel->children("atom", true)->link->attributes();
$filename = $attribute["href"];
或者,如果您想从第一个查询返回的结果中获取
$filename = $initdata['feedlink'];
上面的结果是一个完整的路径,因此如果您只需要该路径中的文件名,请使用此
$feedlink = "http://mywbsite/mydir/lastnightstelevision.xml";
$filename = basename($feedlink);
输出:
lastnightstelevision.xml