public function execute()
{
if (function_exists('curl_init')) {
$ch = curl_init();
if (is_array($this->headers) != false) {
}
curl_setopt($ch, CURLOPT_VERBOSE, $this->debug);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . DS . 'cacert.pem.txt');
if ($this->timeout != false) {
if (function_exists('set_time_limit')) {
@set_time_limit(600);
}
}
$save_to = $this->save_to_file;
$this->save_to_file = false;
$dl = false;
if ($save_to != false) {
$save_to = trim($save_to);
$save_to = str_replace('..', '', $save_to);
$save_to = normalize_path($save_to, false);
if (file_exists($save_to)) {
$dl = true;
$from = filesize($save_to);
curl_setopt($ch, CURLOPT_RANGE, $from . '-');
$fp = fopen($save_to, 'a');
} elseif ($save_to != false) {
$dl = true;
$fp = fopen($save_to, 'w+');
//This is the file where we save the information
}
if (isset($fp) and $fp != false) {
$dl = true;
if (function_exists('set_time_limit')) {
@set_time_limit(600);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
// write curl response to file
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
}
}
if ($dl == false) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
}
curl_setopt($ch, CURLOPT_VERBOSE, true);
$is_new_curl = class_exists('CurlFile', false);
if (is_array($this->post_data) and !empty($this->post_data)) {
$str = http_build_query($this->post_data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
} elseif ($this->fields_string != false) {
curl_setopt($ch, CURLOPT_POST, 1);
if (isset($this->post_data) and is_array($this->post_data) and !empty($this->post_data)) {
if ($is_new_curl == false) {
$str = $this->post_data;
} else {
$str = array_merge($this->post_data, $this->uploads);
}
if (is_array($str)) {
// //$str = http_build_query($str);
$str = $this->buildPostString($str);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
} else {
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->fields_string);
}
}
// grab URL
$result = curl_exec($ch);
if ($dl != false) {
fclose($fp);
}
$this->headers = array();
curl_close($ch);
} else {
$data = $this->post_data;
if (is_array($data)) {
$data = http_build_query($data);
$context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => $data)));
$result = @file_get_contents($this->url, false, $context);
} else {
$result = @file_get_contents($this->url, false);
}
}
return $result;
}