File size: 2.2Kb
<?php
/**
* Free Wallpaper Script
*
* Free Wallpaper Script by Vepa Halliyev is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
*
* @package Free Wallpaper Script
* @author Vepa Halliyev
* @copyright Copyright (c) 2009, Vepa Halliyev, veppa.com.
* @license http://www.veppa.com/free-wallpaper-script/
* @link http://www.veppa.com/free-wallpaper-script/
* @since Version 1.0
* @filesource
*/
class Curl{
static function get($url)
{
//echo '[get('.$url.')]';
if (!function_exists('curl_exec'))
{
$timeout = stream_context_create(array('http' => array('timeout' => 5)));
$content = file_get_contents($url,0,$timeout); // if you don't have curl, try this instead
//echo '[file_get_contents]';
}
else
{
$content = self::getCurl($url);
//echo '[getCurl]';
}
return $content;
}
static function getCurl($url,$post=null)
{
//curl kullanarak external dosya sorgulama ve post gondermek icin kullanilir
//$post is an array=array('field'=>'value');
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
if($post){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$file_contents = curl_exec($ch);
curl_close($ch);
// display file
//echo "file_contents<br>".$file_contents;
return $file_contents;
}
static function curl_get_file($url,$local_file)
{
// echo "<br>Attempting message download for $url<br>";
$out = fopen($local_file, 'wb');
if ($out == FALSE)
{
print "File not opened<br>";
return false;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $out);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
//echo "<br>Error is : ".curl_error ( $ch);
curl_close($ch);
//fclose($handle);
return true;
}
static function containsUrl($url,$find)
{
$arr = explode('/',$url);
$last = array_pop($arr);
list($name,) = explode('.',$last);
return ($name === $find);
}
}