Answer the question
In order to leave comments, you need to log in
PHP: send file downloaded from server1 with post request to server2?
So, for example, there is a picture on server1 server1.ru/file1.jpg
It is necessary to send this file to server2 (server2.ru) with a POST request.
How to do it as quickly and easily as possible?
My suggestion:
To download file1.jpg use:
$fp = @fopen('http://server1.ru/file1.jpg', "rb");<br/>
$fd = @fopen('tmp/tmp_filename', "w");<br/>
if ($fp && $fd) {<br/>
while (!feof($fp)) {<br/>
$st = fread($fp, 4096);<br/>
fwrite($fd, $st);<br/>
}<br/>
}<br/>
@fclose($fp);
Answer the question
In order to leave comments, you need to log in
// читаем файл
$fileString = file_get_contents('http://server1.ru/file1.jpg');
// подготавливаем POST
$params = array('http' => array(
'method' => 'POST',
'content' => $fileString
));
$context = stream_context_create($params);
// посылаем POST, получаем отклик
if($remote = @fopen('http://server2.ru/filesend.php', 'rb', false, $context)){
$response = @stream_get_contents($remote);
}
Interestingly, two servers and the interaction between them are mentioned first. And in the end, I remember about some kind of “client”.
Maybe you don't need to bother with these requests at all. Give the second recipient server a link to the image - let it download it. This way, the scripts of the donor server will not be loaded (if you give a direct link to the image), and you can organize a queue for downloading images from the first server on the second server if there are a lot of such images downloaded at the same time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question