使用PHP在指定URL收集图像并将其存储到数据库中
通常,我希望输入一个URL,然后将该URL处的图像导入数据库 这里有一些代码让我很接近,但也欢迎其他代码 如果我试图将$image作为BLOB存储到数据库中,则会出现错误使用PHP在指定URL收集图像并将其存储到数据库中,php,image,curl,screen-scraping,scraper,Php,Image,Curl,Screen Scraping,Scraper,通常,我希望输入一个URL,然后将该URL处的图像导入数据库 这里有一些代码让我很接近,但也欢迎其他代码 如果我试图将$image作为BLOB存储到数据库中,则会出现错误 <?php class wSpider { var $ch; /// going to used to hold our cURL instance var $html; /// used to hold resultant html data var $binary; /// used f
<?php
class wSpider
{
var $ch; /// going to used to hold our cURL instance
var $html; /// used to hold resultant html data
var $binary; /// used for binary transfers
var $url; /// used to hold the url to be downloaded
function wSpider()
{
$this->html = "http:/";
$this->binary = 0;
$this->url = "";
}
function fetchPage($url)
{
$this->url = $url;
if (isset($this->url)) {
$this->ch = curl_init(); /// open a cURL instance
curl_setopt ($this->ch, CURLOPT_RETURNTRANSFER, 1); // tell cURL to return the data
curl_setopt ($this->ch, CURLOPT_URL, $this->url); /// set the URL to download
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true); /// Follow any redirects
curl_setopt($this->ch, CURLOPT_BINARYTRANSFER, $this->binary); /// tells cURL if the data is binary data or not
$this->html = curl_exec($this->ch); // pulls the webpage from the internet
curl_close ($this->ch); /// closes the connection
}
}
}
$mySpider = new wSpider(); //// creates a new instance of the wSpider
$mySpider->binary = 1; /// turns on the binary transfer mode
$image = $mySpider->fetchPage("http://static.php.net/www.php.net/images/php.gif");
?>
你不需要这些东西 您可以这样做:
$image=file\u get\u contents($url)代码>
然后pdo::prepare(“插入img(?)”代码>你不需要这些东西
您可以这样做:$image=file\u get\u contents($url)代码>
然后pdo::prepare(“插入img(?)”代码>它代表哪一个错误?在每行代码前放四个空格,以便正确设置代码格式。请编辑您的问题并设置代码格式:D(选择代码部分并单击括号)您需要将代码格式设置为更具可读性,然后才能获得帮助。使用文本编辑器的按钮执行此操作。不需要设置格式,因为没有那么难的函数。但是,他没有告诉我们SQL代表哪一个“错误”它代表哪一个错误?在每行代码前放四个空格,以便正确格式化。请编辑您的问题并格式化您的代码:D(选择代码部分并单击括号)您需要将代码格式化为可读性更好的代码,然后才能获得帮助。使用文本编辑器的按钮执行此操作。不需要设置格式,因为没有那么难的函数。然而,他没有告诉我们SQL代表哪个“错误”