PHP: upload file from one server to another server

前端 未结 6 1155
野性不改
野性不改 2020-12-08 12:08

I\'m developing a website in a server and the storage is in another server and I have to deal with that somehow. I nerve experience this case and I found that the solution i

6条回答
  •  一个人的身影
    2020-12-08 12:29

    You may google, there are lots of tutorials on how to work with curl. In your case you need to develop two parts on both servers:

    1. reception form, which will await for file being uploaded (receiver)
    2. curl upload script (sender)

    The sender script could be alike:

    $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://yoursecondserver.com/upload.php');
    curl_exec($ch);
    curl_close($ch);
    

    How to receive file on the second server you may read up in the PHP manual, lots of examples http://php.net/manual/en/features.file-upload.php

    Potentially you might want to use FTP connection, if have it installed on your servers, it might be even easier.

提交回复
热议问题