0

I'm using a php file to load images into my webpage, since they are hosted outside the webroot. Everything works well apart from Facebook not registering the image in an og:image metatag when they are loaded in this way.

Ironically, the page in question is https://www.molecularmagic.net/hosting/the.computing.cafe/www/index.php?t=3b3c55

The metatag in question is:

<meta property="og:image" content="https://www.molecularmagic.net/hosting/the.computing.cafe/www/file.php?f=feature_image.png">

The headers sent along with the image are:

accept-ranges: bytes
cache-control: public, max-age=604800
content-length: 243688
content-type: image/png
date: Sun, 06 Jun 2021 22:56:58 GMT
expires: Thu, 19 Nov 1981 08:52:00 GMT
last-modified: Sun, 06 Jun 2021 23:05:22 +0100
server: LiteSpeed
vary: User-Agent

In this case, Facebook Sharing Debugger gives me this error:

Provided og:image URL, https://www.molecularmagic.net/hosting/the.computing.cafe/www/file.php?f=featured_image.png could not be processed as an image because it has an invalid content type

For other pages, the og:image tag is:

<meta property="og:image" content="http://openmediavault/the.computing.cafe/www/images/feature_image.png?1623012347">

The numbers after the filename are the filemtime to force FB to reload the image if I change it. The headers sent with this image are:

accept-ranges: bytes
cache-control: public, max-age=604800
content-length: 183886
content-type: image/png
date: Sun, 06 Jun 2021 22:27:30 GMT
expires: Sun, 13 Jun 2021 22:27:30 GMT
last-modified: Sun, 06 Jun 2021 20:46:04 GMT
server: LiteSpeed
vary: User-Agent

...and Facebook Sharing Debugger correctly renders the image.

I've tried very hard to make sure that the headers when the image is sent through file.php are as close as possible to the headers sent from a 'real' image file.

I know that this is caused by serving the image through file.php but I cannot see why Facebook would tell me that the image has an invalid content type when the headers look identical.

Can anyone suggest why this might be the case?

MrMills
  • 151
  • 11
  • sanity check.. go to [the image](https://www.molecularmagic.net/hosting/the.computing.cafe/www/file.php?f=feature_image.png) – Lawrence Cherone Jun 06 '21 at 23:16
  • Loads OK for me... – MrMills Jun 06 '21 at 23:17
  • 1
    not for me im getting `File not found: feature_image.png` – Lawrence Cherone Jun 06 '21 at 23:17
  • Yes - you cannot load the image without loading the page first. Load https://www.molecularmagic.net/hosting/the.computing.cafe/www/index.php?t=3b3c55 first and then the image. I've used session variables loaded in the page to locate the image. – MrMills Jun 06 '21 at 23:19
  • 2
    the image needs to be hot linkable, the bot is most likely seeing the text not the image, the same server/ip won't be scrapping both the site and images etc – Lawrence Cherone Jun 06 '21 at 23:21
  • 1
    Damn. That makes sense. I think what I want to do is impossible then? – MrMills Jun 06 '21 at 23:22
  • 1
    network quota is cheap nowadays, is no point preventing access to images, you could even deploy a image/file server `http://images.openmediavault.com/the.computing.cafe/filename.jpg` and use an origin pull cdn, which pulls from the source site, then plop cloudflare in front, then you'll probably find 90% of traffic is cached and doesn't even hit your server – Lawrence Cherone Jun 06 '21 at 23:29
  • Thanks @LawrenceCherone - I disabled hotlinking to files to prevent any access outside the page. However, I'm using the same script for images. I will add a new image.php file to allow hotlinking to images and this will hopefully solve my issue. – MrMills Jun 06 '21 at 23:38

1 Answers1

0

Fixed - thank you. Was completely solved by making the metadata image hotlinkable.

MrMills
  • 151
  • 11