duanlun2827 2010-06-28 20:11
浏览 55
已采纳

用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:

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.

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.

Please help?

  • 写回答

3条回答 默认 最新

  • dtz46697 2010-06-28 20:16
    关注

    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);
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 能给我一些人生建议吗
  • ¥15 mac电脑,安装charles后无法正常抓包
  • ¥18 visio打开文件一直显示文件未找到
  • ¥15 请教一下,openwrt如何让同一usb储存设备拔插后设备符号不变?
  • ¥30 使用quartz框架进行分布式任务定时调度,启动了两个实例,但是只有一个实例参与调度,另外一个实例没有参与调度,不知道是为什么?请各位帮助看一下原因!!
  • ¥50 怎么获取Ace Editor中的python代码后怎么调用Skulpt执行代码
  • ¥30 fpga基于dds生成幅值相位频率和波形可调的容易信号发生器。
  • ¥15 R语言shiny包和ncdf4包报错
  • ¥15 origin绘制有显著差异的柱状图和聚类热图
  • ¥20 simulink实现滑模控制和pid控制对比,提现前者优势