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 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应