-2

Am trying to display image from another server to the dashboard using PHP. I am able to get the file names in the directory and authentication is a success. But unable to view that image using src.

<?PHP
$connection = ssh2_connect('servername', 22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection);

$handle  = opendir('ssh2.sftp://' . intval($sftp) . '/path/');
while (false != ($entry = readdir($handle))){
echo "$entry\n";
echo '<img src="ssh2.sftp://' . intval($sftp) . '/path/'.$entry.'">'; // Not working

}
?>
sam mathew
  • 35
  • 1
  • 7
  • you can't view image from another server with ssh like that, you need to download that image to your server and show them – Surya Mahadi Apr 25 '20 at 10:14

1 Answers1

0
echo '<img src="ssh2.sftp://' . intval($sftp) . '/path/'.$entry.'">'; // Not working

This line didn't work because the src will be load client side, so, it's the client who will ask for ssh2.sftp connexion, and he can't do that.

You have to set src to a public url, usually an url from your server.

So the good way, like was say by Surya Mahadi it's to download the file. If you don't want to store the image, you can encode it in base64 and send it like that.

For more information about ssh2.sftp, read the PHP manual.

Peshigome
  • 1
  • 2