用php将文件上传到另一个php服务器 [英] Upload file with php to another php server

查看:87
本文介绍了用php将文件上传到另一个php服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我并不是在问如何将文件从浏览器上传到php脚本,已经有很多关于此的教程.我问这个问题:

I'm not asking about uploading a file from a browser to a php script, there's plenty of tutorials about that already. I'm asking about this:

我有一个php脚本已接受用户的文件,并且该文件当前位于服务器1的硬盘上.我想使用常规文件将文件从服务器1上载到服务器2的php脚本中Http post协议,因此可以将服务器2上的php脚本编写为标准的文件上传处理程序.

I have a php script that has accepted a file from the user, and the file is currently on the hard disk of server 1. I want to upload the file from server 1 to a php script on server 2, using the regular Http post protocol, so the php script on server 2 can be written as a standard file-upload handler.

我在互联网上找不到任何教程,因为他们都在谈论浏览器-> server1.有关php上传的教程都谈论ftp,但我不想使用该协议.

I cannot find any tutorial on the internet, because they all talk about browser->server1. The tutorials about php upload all talk about ftp, but I don't want to use that protocol.

请帮助?

推荐答案

您可以为此使用CURL.像这样的事情应该做.

You can use CURL for this. Something like this should do it.

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => '@/path/to/file.txt'));
curl_setopt($ch, CURLOPT_URL, 'http://server2/upload.php');
curl_exec($ch);
curl_close($ch);

然后,您可以将server2部分作为常规文件上传进行处理.有关这些选项的更多信息,请参见 curl_setopt() .

You can then handle the the server2 part as a regular file upload. See curl_setopt() for more information on those options.

这篇关于用php将文件上传到另一个php服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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