0

I am having immense trouble trying to show a picture I have on my FTP-Server inside another website. What I've been trying so far, is to show the image inside of an iFrame. My code is the following:

<body>

<?php
$pic = file_get_contents('ftp://username:password@servername.net/image.jpg');
echo "<iframe src=". $pic . "> </iframe>";
?>
</body>

This is basically the code that seemed to work for other users when this question was asked, but instead for me it shows an iframe with the following message:

Not Found

The requested URL was not found on this server. Apache/2.4.29 (Ubuntu) Server at servername.net Port 1234

I really do not know what to try anymore, since I've tried pretty much every solution I found, so I hope one of you has any idea how to help me.

eSeL
  • 13
  • 3

1 Answers1

1

The $pic contains the image data. So you need to encode it as an image. This option could slow down older browsers.

You should display the image in tag. You can combine HTML and PHP better:

<img src="data:image/jpeg;Base64,<?=base64_encode(file_get_contents('ftp://username:password@servername.net/image.jpg'));?>">

If the image is not available for you maybe try to clear your browser cache. If you add a random parameter to the url it will be updated every time. I do not recommend it but you could do it if you want:

<img src="data:image/jpeg;Base64,<?=base64_encode(file_get_contents('ftp://username:password@servername.net/image.jpg?_t='.time()));?>">
CleverSkull
  • 479
  • 3
  • 10
  • Well it does show something now, only that I am pretty sure that this is not the image i want it to show.It shows a small square inside of which is what looks like a paper ripped apart in the middle. If it helps, for the above code, it shows the following html: . By the way, I am using firefox as a browser, so after some short research, it seems to be their broken page icon. – eSeL Oct 24 '20 at 16:09
  • The ripped icon is an error image. There is nothing after the , it means that the image really don't exist. You should check it. – CleverSkull Oct 24 '20 at 16:16