dqc18251 2012-07-04 08:11
浏览 48
已采纳

自动从网络服务器发布文件

I'm trying to make a script that sends a file from my server to another server via POST method. The HTML may look like this:

<form action="https://anotherserver/receive.php" method="POST" enctype="multipart/form-data">
    <input type="file" name="file" />
    <input type="submit" />
</form>

With this part, I can send a file from my computer to another server. But the script should send the file from my webserver, if a condition is true. For example, I create a file on my website, I hit "OK" and the file is automatically sent to the external webserver. Is it possible such a method? Any help is much appreciated.

  • 写回答

1条回答 默认 最新

  • duanjianhe1388 2012-07-04 08:58
    关注

    This code will post a file to another server:

    <?php
        $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_USERAGENT, "Mozilla/4.0 (compatible;)");
        curl_setopt($ch, CURLOPT_URL, 'https://anotherserver/receive.php');
        curl_setopt($ch, CURLOPT_POST, true);
        $post = array(
            "file"=>"/path/to/myfile.jpg",
        );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
        $response = curl_exec($ch);
    ?>
    

    Adapted from: http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)