2015-02-09 59 views
0

我有php rss饲料是工作完美。 我想能够插入rss图像到mysql数据库,我不能这样做。 我已经以BLOB格式设置了我的数据库,以支持图像插入。插入RSS饲料图像到数据库

我的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> 

回答

0

您将需要阅读的文件内容,而不仅仅是URL指向图像文件。

通过使用curl将图像下载到$变量中,然后将其保存到数据库,保存到文件然后读取其内容,然后将其保存到数据库中。

+0

可以请给我一个例子,使用我的代码使用culr方法。 – user3818265 2015-02-09 18:38:20

+0

http://stackoverflow.com/questions/6476212/save-image-from-url-with-curl-php – 2015-02-09 18:45:38