2015-02-09 47 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