send file data using PHP HttpRequest

httprequest, php

Solution

You could use cURL this is a simple example of a HTTP POST :

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.site.com/url");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"key=value&key1=value1");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

// Check response
if ($server_output == "OK") { 

There is an example of POSTing a file string using cURL in this answer

Problem

I have data that is contained within a variable (which can be written as a file), but I am looking to send it to a different server using PHP `HttpRequest`. I thought of using `addRawPostData` but I it is deprecated now and I would prefer not to write the file to the client server then try and send it. If anyone has any ideas let me know. I also attempted to submit the raw data from the variable in a field in a normal `post` but it seems to be corrupted. The file I am attempting to send is a torrent file, if this makes any difference. Thanks again

Original source

Related problems