I
I
ILoveYAnny2017-06-01 20:58:01
linux
ILoveYAnny, 2017-06-01 20:58:01

How correctly in PHP to accept a form on one server, and transfer the file from it to another?

Hello, I have a form that contains data and a file. I get all this on server A. On server A, I need to process the form, and save the file from it on server B. Tell me how to do it right?
ps
Server A - Shared Hosting
Server B - Ubuntu

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2017-06-01
@ILoveYAnny

Option I. NFS mount a folder from server B to server A.
Option II. By means of PHP, immediately send the accepted file to server B - this will slightly lengthen the processing time of the accepted form, but it is the simplest solution. Use cURL and CURLFile :

$ch = curl_init();
curl_setopt_array( $ch, [
  CURLOPT_POST => true,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POSTFIELDS => [
    "file" => new CURLFile("/tmp/" . $tmpFileName) // путь к принятому файлу
  ],
  CURLOPT_URL => "http://server-B.domain.com"
]);

curl_exec( $ch); // выполнить запрос

See cURL options for more details - maybe you need to disable SSL certificate verification, increase the timeout, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question