将rss提要图像插入数据库


insert rss feed image to the database

我有php rss提要,它运行得很好。我希望能够将rss图像插入mysql数据库,但我做不到。我已经将我的数据库设置为BLOB格式,以支持图像插入。

我的php脚本

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<?php
$url = "http://www.albaldnews.com/rss.php?cat=24";
$rss = simplexml_load_file($url);
if($rss)
{
echo '<h1>'.$rss->channel->title.'</h1>';
echo '<li>'.$rss->channel->pubDate.'</li>';
$items = $rss->channel->item;
foreach($items as $item)
{
$title = $item->title;
$link = $item->link;
$published_on = $item->pubDate;
$description = $item->description;
$category = $item->category;
$guid = $item->guid;
echo '<h3><a href="'.$link.'">'.$title.'</a></h3>';
echo '<span>('.$published_on.')</span>';
echo '<p>'.$description.'</p>';
echo '<p>'.$category.'</p>';
echo '<p>'.$guid.'</p>';
echo "<img src='"" . (string)$item->enclosure['url'][0] . "'">";
}
}
?> 
</body>
</html>

您需要读取文件内容,而不仅仅是指向图像文件的url。

要么使用curl将图像下载到$variable中,然后将其保存到数据库中,然后保存到文件中,然后读取其内容,然后将它保存在数据库中。