远程文件上传

时间:2011-08-15 07:07:53

标签: php file upload

首先,对于更多帖子的版主,我很抱歉,

我在我的控制面板中,上传文件页面

但我希望在另一台服务器上上传文件< - 我有两台服务器

第一个服务器控制面板(上传页面)网址是

first_server.com/admin/upload.php

我的第二个服务器链接是

files.second_server.com

我如何从第一台服务器上传文件到第二台服务器?

没有重定向到第二台服务器

我的第一个服务器内容是 - upload.php

<form -- action=i dont know what i should set in action>
<input name=myfile type=file>
<input type=submit>
</form>

第二个服务器文件是 - proccess.php

if($_FILE['myfile']){
move_uploaded_file.......
//print the file link , to get it by my first page on first server
echo $second_server_full_path . '/' . $_FILE['myfile']['name'];
}

所以..我如何通过curl或file_get_content完成这项工作

我认为file_get_content会很好..但是最大超时时间太短了!

请帮忙!

1 个答案:

答案 0 :(得分:2)

  

我如何从第一台服务器上传文件到第二台服务器?   没有重定向到第二个服务器

通过重定向,我假设您的意思是将发布请求发送到第二台服务器。

起初,从技术上讲,这是不可能的。表单的数据将被发送到指定的服务器,如果要求您将文件保存在第二台服务器上,则第二台服务器需要接收数据。

如果您不想通过浏览器将文件发送到第二台服务器,则需要通过第一台服务器将文件发送到第二台服务器。例如,您可以在第二台服务器上创建网络共享,然后在第一台服务器上的提交脚本中,通过共享将文件移动到第二台服务器。

通过curl传输文件(注意:文件路径前面的@):

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
    "myfile"=>"@/path/to/myfile.jpg",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$response = curl_exec($ch);

而不是使用curl,Supported Protocols and Wrappers可能值得研究,例如只需通过FILE / FTP / SSH传输文件。