I created a simple image on a php page, code is below.
I need to take the url of this image as a direct link for other websites.
I tried the same code on a webhosting provider and everything works as it should, but when I use the same code on my vps, it doesn’t work as a direct link.
If I check from web browser they’re identical so what am I missing?
I also noticed that if I use it on Telegram for example, only the one which works generate a thumbnail.
<?php
header("Content-type: image/png");
$im = imagecreatefrompng("image/orange.png");
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$font = 'font/font.ttf';
$string = "test";
imagettftext($im, 20, 0, 20, 230, $white, $font, $string);
imagepng($im);
imagedestroy($im);
?>
EDIT : Could it affect the fact that to access the link in vps I use the IP adress of the machine while for the webhosting I use their domain?
2
Answers
There are a catalog of reasons why it might not work – far too many to list here. But the reason I’m posting is that you don’t seem to have made any attempt to diagnose the problem yourself. Maybe you don’t know how.
Your first step is to make sure the logging is working as it should on your platform. Write some code with deliberate mistakes in it. Make sure you can see those mistakes in your logs (and only in your browser for a dev environment). If not, find out why.
Then try running your image script – and see if it is throwing any errors.
Another good place to look for issues is in web developer tools – a non-200 status code should be a red flag that there is something very wrong with your code.
But you also need to learn how to code defensively. Your code should detect issues and respond to them sensibly. Particularly when the thread of execution touches things outside the PHP runtime (like files).
There is a whole lot other you might check for in your code – but they will mostly be caught/reported by PHP.
you should be able to use this code in your vps using an IP.
follow these questions/steps to find the problem :
there might be a file missing for example orange.png or font.ttf