我正在开发我的php博客项目。如何将博客文章中的图像存储到目录中?
博客文章可能包含强大,斜体,网络链接,列表,图像等。
(我是php初学者。提前致谢。)
答案 0 :(得分:0)
这里让我告诉你如何做到这一点:
PHP Simple HTML DOM Parser:
LINK:http://simplehtmldom.sourceforge.net/
从链接下载所有图片的示例代码:
注意:以下代码将下载代码中提供的网址上显示的所有图片。
<?php
// Make sure to include the library php file
include('simple_html_dom.php');
//URL To Download Images From
$url = "http://www.google.com/"
// Create DOM from URL or file
$html = file_get_html($url);
// Find all images
$i=1;
foreach($html->find('img') as $element) {
$url = $element->src;
$img = "/my_folder/image_".$i.".png";
file_put_contents($img, file_get_contents($url));
$i++;
}
?>