NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Show random image

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
7 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 02-21-2008, 11:00 AM THREAD STARTER               #1 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
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(0count($images) - 1)];
// Get random image.

switch (strtolower(substr($image, -44)))
{
    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
????: NamePros.com http://www.namepros.com/code/435390-show-random-image.html

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");
????: NamePros.com http://www.namepros.com/showthread.php?t=435390
        
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.
    
}
}

?>
Last edited by Daniel; 03-06-2008 at 11:48 AM.
Daniel is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 07:20 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger