gee, sorry for being such a newb, but what is CURL?
thanks so much for going over the regex. hopefully i will be able to use it soon. i'm terribly excited about the possibilities of this code for making mosaics on my pages...
CURL is a php lib that allows you to create connections to remote servers with protocols such as HTTP, FTP etc, just like the built in stream functions . PHP needs to be compiled with CURL support however, but most hosting supports CURL.
CURL PHP Manual: http://php.net/curl
Heres a good simple class for CURL I found on the php CURL manual page:
[PHP]<?php
/*
Sean Huber CURL library
This library is a basic implementation of CURL capabilities.
It works in most modern versions of IE and FF.
==================================== USAGE ====================================
It exports the CURL object globally, so set a callback with setCallback($func).
(Use setCallback(array('class_name', 'func_name')) to set a callback as a func
that lies within a different class)
Then use one of the CURL request methods:
get($url);
post($url, $vars); vars is a urlencoded string in query string format.
Your callback function will then be called with 1 argument, the response text.
If a callback is not defined, your request will return the response text.
*/
class CURL {
var $callback = false;
var $cookiejar = 'cookie.txt';
var $cookiefile = 'cookie.txt'
function setCookieJar($file_path) {
var $cookiejar = $file_path;
}
function setCookieFile($file_path) {
var $cookiefile = $file_path;
}
function setCallback($func_name) {
$this->callback = $func_name;
}
function doRequest($method, $url, $vars) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiejar);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile);
if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
}
$data = curl_exec($ch);
curl_close($ch);
if ($data) {
if ($this->callback)
{
$callback = $this->callback;
$this->callback = false;
return call_user_func($callback, $data);
} else {
return $data;
}
} else {
return curl_error($ch);
}
}
function get($url) {
return $this->doRequest('GET', $url, 'NULL');
}
function post($url, $vars) {
return $this->doRequest('POST', $url, $vars);
}
}
?>
[/PHP]
ref: http://php.net/curl
I've added the two functions:
[PHP]function setCookieJar($file_path) {
var $cookiejar = $file_path;
}
function setCookieFile($file_path) {
var $cookiefile = $file_path;
}[/PHP]
This will allow you to set paths for your cookies to be saved in. Usually you would want to use a file below your webroot, that cannot be read.
IF just for the flickr images, you don't need those two functions... but say if you wanted to use it for the flickr API, which would need authentication for some requests, it would be best to protect the cookies from being read by anyone.
For flickr you'd use it something like:
[PHP]// you need curl since you cant use the php stream functions
$CURL = new CURL();
$php = $CURL->get("http://api.flickr.com/services/feeds/photos_public.gne?tags=$tags&format=php");
// since you cant use include() you'll need to strip the php tags
$php = str_replace(array('<?php', '?>'), '', $php);
// then you need to evaluate the php within, as would be done with an include()
eval($php);[/PHP]
I havent tested that but, it should work. Hope that gives you a start on getting the mosaics done.. :)