使用来自FTP服务器的图像作为图像源 [英] Using images from FTP server as image source

查看:146
本文介绍了使用来自FTP服务器的图像作为图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在如何从不同的FTP服务器访问映像时遇到问题,然后将其用作

 < img src ='来自不同服务器的路径'> 

目前这里是我搜索的结果

 < img src =ftp:// username:password@my_ftp_ip_address/Images/imagename.jpg/> 

但我不希望任何人在FTP上查看我的登录凭据。有没有其他的方法来做到这一点,或只是用上面的方法隐藏登录凭据?



PS我使用PHP和Linux作为文件服务器。

解决方案

您必须创建一个充当图像源的PHP脚本(您将在< img src = ...> 属性。该脚本将通过从FTP服务器下载图像产生。



(例如 image.php )的实现方式是: ('Content-Type:image / jpeg');

echo file_get_contents('ftp:// username: password@ftp.example.com/path/image.jpg');

然后你使用它在HTML中:

 < a src =image.php/> 

(假设 image.php 在与您的HTML页面相同的文件夹)




该脚本使用 FTP URL封装器。如果您的网络服务器不允许这样做,那么您必须通过FTP功能更加努力。请参阅
PHP:如何从FTP服务器将文件读入变量?






尽管对于一个非常正确的解决方案,您应该提供更多与该文件相关的HTTP标头,如 Content-Length Content-Disposition 。为此,请参阅通过PHP脚本将文件从FTP服务器下载到具有Content-Length标头的浏览器,而不将文件存储在Web服务器上


I'm currently having problem on how to access an image from a different FTP server then use it as

<img src = 'Path from different server'>

Currently here is the result I've got from searching

<img src="ftp://username:password@my_ftp_ip_address/Images/imagename.jpg"/>

But I wouldn't want anybody to view my login credentials on FTP. Is there any other way to do it or just hide the login credentials with the method above?

PS I'm using PHP and Linux as a file server.

解决方案

You have to create a PHP script that acts as the image source (you will use it in the <img src=...> attribute. The script will "produce" the image by downloading it from FTP server.

The most trivial way to implement such a script (say image.php) is:

<?

header('Content-Type: image/jpeg');

echo file_get_contents('ftp://username:password@ftp.example.com/path/image.jpg');

And then you use it in the HTML like:

<a src="image.php" />

(assuming the image.php is in the same folder as your HTML page)


The script uses FTP URL wrappers. If that's not allowed on your web server, you have to go the harder way with FTP functions. See PHP: How do I read a file from FTP server into a variable?


Though for a really correct solution, you should provide more HTTP headers related to the file, like Content-Lengthand Content-Disposition. For this, see Download file via PHP script from FTP server to browser with Content-Length header without storing the file on the web server.

这篇关于使用来自FTP服务器的图像作为图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆