需要使用PHP和SSH2_CONNECT显示来自另一台服务器的图像

问题描述 投票:-1回答:1

正在尝试使用PHP将图像从另一台服务器显示到仪表板。我能够获取目录中的文件名,并且身份验证成功。但是无法使用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

}
?>
php php-7 php-5.6 php-7.2
1个回答
0
投票
echo '<img src="ssh2.sftp://' . intval($sftp) . '/path/'.$entry.'">'; // Not working

此行不起作用,因为src将被加载客户端,因此,是客户要求ssh2.sftp连接,但他不能这样做。

您必须将src设置为公共URL,通常是服务器中的URL。

所以,好方法,就像Surya Mahadi所说的,是下载文件。如果您不想存储图像,则可以在base64中对其进行编码,然后将其发送。

有关ssh2.sftp的更多信息,请阅读PHP manual

© www.soinside.com 2019 - 2024. All rights reserved.