k9b
k9b

Reputation: 1493

Referencing a .php file from an html img src tag

In my getimage.php file, I have a function that returns an image and an echo statement

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

Then in my index.html I have the following code

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

Now obviously I know im doing something wrong, as in the html its a broken picture. I am assuming that setting the src as a .php file doesnt actually execute getimage.php

Any ideas/help?

Thanks!

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;
    }

Upvotes: 0

Views: 3905

Answers (1)

Rick D.
Rick D.

Reputation: 130

Depending on the location of getimage.php, you will probably have to specify the relative URL path, such as

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

Assuming getimage.php is at the root of your website.

Upvotes: 1

Related Questions