PHP: upload file from one server to another server

前端 未结 6 1154
野性不改
野性不改 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:28

    You can upload file on another server using posting the file.

    $request = curl_init('http://example.com/');
    
    // send a file
    curl_setopt($request, CURLOPT_POST, true);
    curl_setopt(
        $request,
        CURLOPT_POSTFIELDS,
        array(
          'file' => '@' . realpath('example.txt')
        ));
    
    curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
    echo curl_exec($request);
    
    curl_close($request);
    

    You can handle the Uploaded file using $_FILES['file']

提交回复
热议问题