0

通常、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 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");

?>
4

1 に答える 1

5

あなたはそのすべてのものを必要としません。

できるよ:$image = file_get_contents($url);

その後pdo::prepare("INSERT INTO img (?, ?)");

于 2011-06-08T17:11:55.790 に答える