Upload file with php to another php server

后端 未结 3 1524
自闭症患者
自闭症患者 2020-12-07 15:48

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 t

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 16:37

    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.

提交回复
热议问题