Answer the question
In order to leave comments, you need to log in
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
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); // выполнить запрос
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question