Home  >  Article  >  Backend Development  >  将文件从远程下载后不经硬盘保存,直接上传至另一服务器,怎么做啊

将文件从远程下载后不经硬盘保存,直接上传至另一服务器,怎么做啊

WBOY
WBOYOriginal
2016-06-23 14:13:38930browse

小弟正做一项目,需用php将图片从远程下载后,再通过ftp上传到另一服务器,下载至硬盘,这个偶常做,用ftp上传本地文件,这个也会,可不经过本地硬盘,直接传递,怎么做啊,哪位大侠帮下吧


回复讨论(解决方案)

file_put_contents('ftp://用户名:口令@ftp主机/文件名', file_get_contents('http://远程主机/文件名'));

已有了与ftp服务器连接上的$ftp_stream,如果利用file_put_contents('ftp://用户名:口令@ftp主机/文件名', file_get_contents('http://远程主机/文件名')),那我还需再与ftp服务器再连接一次,势必造成资源的浪费。
我想:能否像ftp_put($ftp_stream,$remote_file, $local_file)一样利用已有的$ftp_stream,实现file_put_contents()的直接将内容写入文件的功能呢?
也就是说,有没有类似于ftp_put($ftp_stream,$remote_file, $string)的函数呢?

我想你的脑子是进水了

ftp 扩展提供有 ftp_fput 函数,为什么不用呢?

$fp = fopen('http://远程主机/文件名', 'rb');
ftp_fput($ftp_stream, $remote_file, $fp);

呵呵,写代码写的一点儿也不想动脑子了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn