I'm trying to upload some files to a web-server via PUT.
I'm using Phil Sturgeon's REST library on the server side.
The client is a PHP application using curl to generate the requests.
...
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch,CURLOPT_INFILE,$fp);
curl_setopt($ch,CURLOPT_INFILESIZE,$fsize);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$headarray = array();
if ($api_key)
$headarray[] = 'X-API-KEY:'.$api_key;
$headarray[] = "Content-Type: application/octet-stream";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headarray);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_exec($ch);
...
The data is being received. However when I look at $this->put() on the server side, I get an array which looks like my input file got parsed. I would like the entire file to be available as one string, as raw data.
I tried to use fopen("php://input", "r");
instead, but it's blank. Presumably this has already been consumed by the REST library.
I haven't written a PUT request before using curl, so maybe something is wrong on that side of things.
Is there an alternative to $this->put() which will give me the raw input rather than an array.
It seems that I may have to put my file into a parameter, if so, how to do that with curl when I'm using CURLOPT_INFILE? I want to be able to send large files without running into php's memory limit.