PHP: send file downloaded from server1, post the request to server2?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
13 views
So, there are for example the picture on сервере1 server1.ru/file1.jpg

You need to send the file to server2 (server2.ru) the POST request.

How to do this quickly and easily?


My suggestion:

For download file1.jpg use:
$fp = @fopen('http://server1.ru/file1.jpg', "rb");
$fd = @fopen('tmp/tmp_filename', 'w');
if ($fp && $fd) {
while (!feof($fp)) {
$st = fread($fp, 4096);
fwrite($fd, $st);
}
}
@fclose($fp);


Then use CURL to send the file tmp/ $ tmp_filename on server2.


Maybe there's a faster way?


ps: wouldn't it be great to do all of the above on the client side with the help of arbitrary to some jQuery and ship the server with this crap =)
by | 13 views

2 Answers

0 like 0 dislike
// read the file $fileString = file_get_contents('http://server1.ru/file1.jpg'); // prepare POST $params = array('http' => array( 'method' => 'POST', 'content' => $fileString )); $context = stream_context_create($params); // send POST, get a response if($remote = @fopen('http://server2.ru/filesend.php', 'rb', false, $context)){ $response = @stream_get_contents($remote); } 

The source of the method: "HTTP POST from PHP, without cURL" (author Wez Furlong, the code posted on November 15, 2006, upgraded 23 may 2010).
by
0 like 0 dislike
Interestingly, the first mentioned two servers and the interaction between them. And in the end comes to mind about a "client".
\r
Maybe it is not necessary with these queries suffer. To give the second server to the recipient the link to the picture — he download. So will not load the server scripts a donor (if you give a direct link to the picture), and on the second server to organize the download queue pictures from the first server, if such symbols, at the same time downloadable, will be very much.
by

Related questions

0 like 0 dislike
1 answer
asked Apr 9, 2019 by alexanderqwert
0 like 0 dislike
2 answers
asked Apr 9, 2019 by noobwpjs
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
25,705 users