Need help making simple random images

Reply

Join Date: Jul 2006
Posts: 174
Reputation: tefflox is an unknown quantity at this point 
Solved Threads: 1
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Re: Need help making simple random images

 
0
  #11
Nov 10th, 2006
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...
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,083
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Need help making simple random images

 
0
  #12
Nov 11th, 2006
Originally Posted by tefflox View Post
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..
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum


Views: 4330 | Replies: 11
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC