This is my code
<?php //if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once APPPATH."/libraries/REST_Controller.php";
require_once APPPATH."/libraries/echosign.php";
class Document_management extends Rest_Controller
{
public function get_access_token_get()
{
$echoSign = new EchoSign();
$ch = curl_init('https://secure.echosign.com/api/rest/v2/auth/tokens');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($echoSign->echosign_creds));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = json_decode(curl_exec($ch));
curl_close($ch);
return $result->accessToken;
}
public function get_agreements_get()
{
$accessToken = array("Access-Token: ".$this->get_access_token_get());
$ch = curl_init('https://secure.echosign.com:443/api/rest/v2/agreements');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $accessToken);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$result = json_decode(curl_exec($ch));
curl_close($ch);
$agreements = array(
"agreementId" => $result->userAgreementList[0]->agreementId,
"name" => $result->userAgreementList[0]->name,
);
return $agreements;
}
public function get_form_data_get($headers, $agreements)
{
$filepath = APPPATH."files/".$agreements['name']."csv";
$url = 'https://secure.echosign.com:443/api/rest/v2/agreements/'.$agreements['agreementId'].'/formData';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
//header("Content-type: text/csv");
//header("Content-Disposition: attachment; filename=".$filepath);
$result = curl_exec($ch);
//echo "<pre>"; print_r($result); echo "</pre>"; exit();
curl_close($ch);
}
public function download_file_get()
{
$headers = array("Access-Token: ".$this->get_access_token_get());
$agreements = $this->get_agreements_get();
$this->get_form_data_get($headers, $agreements);
}
}
?>
The output in the browser just sends the RAW data of the form in this format
"completed","email","role","first","last","title","company","agreementId","firstname","lastname" "2014-11-04 15:55:44","abe.taha@gmail.com","SIGNER","Abe","Taha","Web Developer","","2AAABLblqZhDrvBK47mPKPZW-VSAJKDHASFT42ESlPxOjYphH4C0A5_adasdasda6qnFCy2idJ8*","ABE","TAHA"
I don't know how to store the stream in a variable / even explode it somehow to store it in a database.
I have tried using php://input or readfile and other options to read the stream but dont understand how to format the data