简体   繁体   中英

insert rss feed image to the database

I have php rss feed which is working perfect. I want to be able to insert the rss image into mysql database, which I couldn't do it. I already setup my database in BLOB format, to support image insertion.

My php script

<!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>

You will need to read the file content, not just the url pointing to the image file.

Either download the image by using curl into a $variable, then save it to database, on save it to a file then read its content then save it in your database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM