如何使用PHP

时间:2019-05-26 22:35:45

标签: php curl google-chartwrapper

我正在尝试从google API创建图像和QR码并将其插入到我的数据库中,稍后我将在我的网站上显示该图像。我有https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=123456这个网址,我想查看数据库中的图片。

 $servername = "localhost";
    $dbUsername = "root";
    $dbPassword = "";
    $dbName = "mydb";

    $conn = mysqli_connect( $servername, $dbUsername, $dbPassword, $dbName);

    if(!$conn)
    {
    die("Connection with db not succesful".mysqli_connect_error());
    }

function getImage($url){
        $ch = curl_init ($url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
        $resource = curl_exec($ch);
        curl_close ($ch);
        return $resource;
    }
    $image=imagecreatefromstring(getImage("https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=123456"));

0 个答案:

没有答案