从html img src标签中引用.php文件


Referencing a .php file from an html img src tag

在我的getimage.php文件中,我有一个返回图像和echo语句的函数

function getPicture(){
}
header("Content-Type: image/png");
echo getPicture(); 

然后在我的index.html中我有以下代码

<body>
        <img src="getimage.php" />
</body>

现在显然我知道我做错了什么,因为在html中它是一个破碎的图片。我假设将src设置为。php文件实际上不会执行getimage.php

任何想法/有帮助吗?

谢谢!

function getPicture()
    {
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL, 'image url');
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer XXXX'));
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
        $picture = curl_exec($ch);
        curl_close($ch);
        return $picture;
    }

根据getimage.php的位置,您可能需要指定相对URL路径,例如

<img src="/getimage.php" />

假设getimage.php在你的网站的根目录