curlHandle == '' ) $this->curlHandle = curl_init(); } public function __destruct() { //if( $this->curlHandle != '' ) curl_close($this->curlHandle); } /* uploadFile *$fileName = the file to be uploaded *success: return the CURL transmission *error: return string */ public function uploadFile($fileName) { $tmp = ''; $fp = ''; if($fileName != '' || file_exists($fileName) ) { $fp = fopen($fileName, 'rb'); $this->setCurlOptions(CURLOPT_CONNECTTIMEOUT, 10); $this->setCurlOptions(CURLOPT_POST, true); $this->setCurlOptions(CURLOPT_RETURNTRANSFER, true); $this->setCurlOptions(CURLOPT_UPLOAD, true); $this->setCurlOptions(CURLOPT_INFILE, $fp); $this->setCurlOptions(CURLOPT_INFILESIZE, filesize($fileName)); $tmp = curl_exec($this->curlHandle); fclose($fp); return $tmp; }else{ return 'Bad file name: ' . $fileName; } } /* submitData *$type = type of submission. options: post or get *$header = array used to submit different headers with the get/post */ public function submitData($type='post', $headers='') { //setup common options for CURL $this->setCurlOptions(CURLOPT_RETURNTRANSFER, true); $this->setCurlOptions(CURLOPT_CONNECTTIMEOUT, 10); $this->setCurlOptions(CURLOPT_UPLOAD, false); if( $headers ) $this->setCurlOptions(CURLOPT_HTTPHEADER, $header); if( $type == 'post' ){ //setup CURL for post $this->setCurlOptions(CURLOPT_POST, true); }elseif( $type == 'get' ){ //setup cURL for get $this->setCurlOptions(CURLOPT_HTTPGET, true); } return curl_exec($this->curlHandle); } //helper funcs //set the options for cURL public function setCurlOptions($key, $value) { curl_setopt($this->curlHandle, $key, $value); } //retrieve the cURL transfer details //param: $option - retrieve specific detail public function getTransferDetails($option = '') { return $option != '' ? curl_getinfo($this->curlHandle, $option) : curl_getinfo($this->curlHandle); } //returns the last error for current cURL session public function getLastError() { return curl_error($this->curlHandle); } }