Sending a file via PUT to codeigniter REST_Controller

I am trying to upload some files to a web server via PUT.

I am using the server side Phil Sturgeon REST library.

A client is a PHP application that uses curl to generate 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);
...

Data is accepted. However, when I look at $ this-> put () on the server side, I get an array that looks like my input file received parsing. I would like the whole file to be available as a single line, as input.

I tried using fopen("php://input", "r");instead, but it is empty. Presumably, this has already been consumed by the REST library.

I did not write a PUT request before using curl, so there may be something wrong with this.

Is there an alternative to $ this-> put () that will give me the original input, not an array.

, , , , , , CURLOPT_INFILE? , , php.

+3
1

... :

REST_Controller.php - ~ 950

protected function _parse_put()
{
    // It might be a HTTP body
    if ($this->request->format)
    {
        $this->request->body = file_get_contents('php://input');
    }

    // If no file type is provided, this is probably just arguments
    else
    {
        parse_str(file_get_contents('php://input'), $this->_put_args);
    }

}

if , : $this->request->body. if , parse_str, $this->put() ( array_flip ). .

, , $this->request->format true; , cURL,

Fatal error:  Uncaught exception 'Exception' with message 'Format class does not support conversion from "stream".' in /Users/mycpu/Sites/ci-rest/application/libraries/Format.php:51
Stack trace:
#0 /Users/mycpu/Sites/ci-rest/application/libraries/Format.php(31): Format->__construct('Lorem ipsum Ut ...', 'stream')
#1 /Users/mycpu/Sites/ci-rest/application/libraries/REST_Controller.php(251): Format->factory('Lorem ipsum Ut ...', 'stream')
#2 /Users/mycpu/Sites/ci-rest/system/core/CodeIgniter.php(308): REST_Controller->__construct()
#3 /Users/mycpu/Sites/ci-rest/index.php(202): require_once('/Users/mycpu...')
#4 {main}
  thrown in /Users/mycpu/Sites/ci-rest/application/libraries/Format.php on line 51

, , parse_str -

array_push($this->_put_args, file_get_contents('php://input'));

php://input

$p = $this->put();
$p[0];//contents of file

, .

+1

All Articles