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

0 like 0 dislike
So, there are for example the picture on сервере1

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

How to do this quickly and easily?

My suggestion:

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

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 | 42 views

2 Answers

0 like 0 dislike
// read the file $fileString = file_get_contents(''); // prepare POST $params = array('http' => array( 'method' => 'POST', 'content' => $fileString )); $context = stream_context_create($params); // send POST, get a response if($remote = @fopen('', '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).
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".
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.

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,187 answers
40,796 users