[advanced search]
Next Live Event: NamePros Live Auction, May 23rd at 6PM EDT
Results from the May 8th live auction are here.
15 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 02-21-2008, 11:00 AM   · #1
Daniel
Danltn.com
 
Daniel's Avatar
 
Name: Daniel Neville
Location: Danltn.com / Nottingham, UK
Trader Rating: (65)
Join Date: May 2007
Posts: 1,162
NP$: 638.56 (Donate)
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
Ethan Allen Fund Ethan Allen Fund
Show random image

Someone asked for a script that would show a random image, only took a few minutes to write, so I thought I might as well share it here.

PHP Code:
<?php

/**
* Danltn | http://danltn.com/
* No warranty is given to code used.
* I'm scared of lawsuits.
*/

$images = array();

$images[] = 'http://www.escapistmagazine.com/global/media/images/articles/folder/120/zeropunctuation_logo.png';
$images[] = 'http://www.google.com/images/experimental.gif';
$images[] = 'http://www.w3.org/2001/tag/2007/05/TagThursDiagram1.JPG';

// Add as many as you like here.

$image = $images[rand(0, count($images) - 1)];
// Get random image.

switch (strtolower(substr($image, -4, 4)))
{
    case
"jpeg":
    case
".jpg":
        
$ctype = "image/jpg";
        break;
    case
".gif":
        
$ctype = "image/gif";
        break;
    case
".png":
        
$ctype = "image/png";
        break;
}
// Find the content type, based on the last 4 characters, I could add GDLib here, but I haven't, this was a quick script.

$file = @file_get_contents($image);
// Get the file

if ($file)
{
    
// Only if the file has successfully been 'grabbed'.
    
$len = strlen($file);
    
// Get the length to be kind to the browser.
    
if (!headers_sent())
    {
        
header("Pragma: public");
        
header("Expires: 0");
        
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        
header("Cache-Control: public");
        
// Set headers.
        
header("Content-Type: $ctype");
        
// Set content type as correct image.
        
header("Content-Length: " . $len);
        
// Be kind to the browser by saying the length.

        
echo $file;
        
// If it all checks out, send the image.
    
}
}

?>


Please register or log-in into NamePros to hide ads

Last edited by Daniel : 03-06-2008 at 11:48 AM.
Daniel is offline   Reply With Quote
Reply

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


Site Sponsors
Thousand Dollar Profits Get Me Visits Proof is in the Parking
Advertise your business at NamePros
All times are GMT -7. The time now is 06:22 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0