/ Published in: PHP
cURL Wrapper
Expand |
Embed | Plain Text
<?php class curl { CURLOPT_RETURNTRANSFER => true, // return the web page CURLOPT_HEADER => false, // don't return the headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)", // set a normal looking useragent CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout CURLOPT_TIMEOUT => 120, // timeout CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); public function __construct() { } public function getPage($url) { $p = curl_init($url); curl_setopt_array($p, $this->options ); $content = curl_exec($p); if(!$content) { throw new \Exception(curl_error($p) . ' ERROR CODE ' . curl_errno($p)); } $header = curl_getinfo($p); curl_close($p); $header['content'] = $content; return $header; } public function downloadFile($url, $filePath) { $this->options[CURLOPT_URL] = $url; $this->options[CURLOPT_FILE] = $fp; $p = curl_init(); curl_setopt_array($p, $this->options); $file = curl_exec($p); curl_close($p); } }
You need to login to post a comment.
