Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 12-30-2012, 05:31 AM   #1
nico-t
emperor of my world
 
Join Date: Aug 2004
Location: nethalands
Posts: 29,903
Simple image rotation script

Been looking all over for this. But all i see is script rotating 1 image.

i've got about a 100 images.
I want to display for example 5 of these images randomly every page load (without doubles).
If some images get repeated onload it doesnt matter, as long as there aren't doubles in every row of 5.
All the pics need to link to a unique url too.

Suggestions?
nico-t is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-30-2012, 05:33 AM   #2
DWB
Registered User
 
Industry Role:
Join Date: Jul 2003
Location: Encrypted. Access denied.
Posts: 31,779
WOJ has a simple script that will do exactly that.
DWB is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-30-2012, 05:42 AM   #3
Oracle Porn
Affiliate
 
Oracle Porn's Avatar
 
Industry Role:
Join Date: Oct 2002
Location: Icq: 94-399-723
Posts: 24,433
Option 1: http://ma.tt/scripts/randomimage/

Option 2: http://randaclay.com/tips-tools/mult...ge-php-script/

Option 3:
Code:
<?php
define('BASE_DIR', '/var/www/mysite/images/'); // Where are your images?
define('IMAGE_LIMIT', 10); // how many images to show?

$files     = glob(BASE_DIR.'*');
$images = Array();

if(empty($files)) {
    die("Hey, dude, there are no files. What happened?");
}

foreach($files as $v) {
    if(is_dir($v)) {
        foreach($files as $v) { // This should be a function which can loop through further sub directories if needed
            //get exif image type, if it's an image append to array
            $images[] = $v;
        }
    } else {
        $images[] = $v;
    }
}

shuffle($images); // Randomise the array
for($i=0;$i<IMAGE_LIMIT;$i++) {
    $img = $images[$i];
    if(empty($img)) {
        break; // Might be best doing a foreach above whilst keeping $i as a loop counter and breaking the loop once you reach the limit
    }
    $img_src = end(explode("/", $img));
    echo "<img src='{$img_src}'/>";
}
__________________


Oracle Porn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-30-2012, 05:50 AM   #4
seeandsee
Check SIG!
 
seeandsee's Avatar
 
Industry Role:
Join Date: Mar 2006
Location: Europe (Skype: gojkoas)
Posts: 50,945
Quote:
Originally Posted by Oracle Porn View Post
Option 1: http://ma.tt/scripts/randomimage/

Option 2: http://randaclay.com/tips-tools/mult...ge-php-script/

Option 3:
Code:
<?php
define('BASE_DIR', '/var/www/mysite/images/'); // Where are your images?
define('IMAGE_LIMIT', 10); // how many images to show?

$files     = glob(BASE_DIR.'*');
$images = Array();

if(empty($files)) {
    die("Hey, dude, there are no files. What happened?");
}

foreach($files as $v) {
    if(is_dir($v)) {
        foreach($files as $v) { // This should be a function which can loop through further sub directories if needed
            //get exif image type, if it's an image append to array
            $images[] = $v;
        }
    } else {
        $images[] = $v;
    }
}

shuffle($images); // Randomise the array
for($i=0;$i<IMAGE_LIMIT;$i++) {
    $img = $images[$i];
    if(empty($img)) {
        break; // Might be best doing a foreach above whilst keeping $i as a loop counter and breaking the loop once you reach the limit
    }
    $img_src = end(explode("/", $img));
    echo "<img src='{$img_src}'/>";
}
Hi, thanks for this code. Can you point me to some good php tutorial site, i have experience in programing (c, c++, basic, even pascal) but i need good site to learn some step by step php code?
__________________
BUY MY SIG - 50$/Year

Contact here

Last edited by seeandsee; 12-30-2012 at 05:51 AM..
seeandsee is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-30-2012, 05:53 AM   #5
just a punk
So fuckin' bored
 
just a punk's Avatar
 
Industry Role:
Join Date: Jun 2003
Posts: 32,384
Assuming that all image URL's are stored in "images.txt" (one URL per line), the code will be as simple as this:
Code:
$images = file('images.txt');
shuffle($images);
for ($i = 0; $i < min(5, count($images)); $i++) {
    echo '<img src="' . trim($images[$i]) . '" />';
}
__________________
Obey the Cowgod
just a punk is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-30-2012, 06:33 AM   #6
nico-t
emperor of my world
 
Join Date: Aug 2004
Location: nethalands
Posts: 29,903
Quote:
Originally Posted by Oracle Porn View Post
Option 1: http://ma.tt/scripts/randomimage/

Option 2: http://randaclay.com/tips-tools/mult...ge-php-script/

Option 3:
Code:
<?php
define('BASE_DIR', '/var/www/mysite/images/'); // Where are your images?
define('IMAGE_LIMIT', 10); // how many images to show?

$files     = glob(BASE_DIR.'*');
$images = Array();

if(empty($files)) {
    die("Hey, dude, there are no files. What happened?");
}

foreach($files as $v) {
    if(is_dir($v)) {
        foreach($files as $v) { // This should be a function which can loop through further sub directories if needed
            //get exif image type, if it's an image append to array
            $images[] = $v;
        }
    } else {
        $images[] = $v;
    }
}

shuffle($images); // Randomise the array
for($i=0;$i<IMAGE_LIMIT;$i++) {
    $img = $images[$i];
    if(empty($img)) {
        break; // Might be best doing a foreach above whilst keeping $i as a loop counter and breaking the loop once you reach the limit
    }
    $img_src = end(explode("/", $img));
    echo "<img src='{$img_src}'/>";
}
I'm using the 3rd option now, and added some code to display unique links for every image begin shown, between these last lines of code:
Code:
    $img_src = end(explode("/", $img));
    echo "<img src='{$img_src}'/>";
}
\

I have added some lines to assign imagename to the url for each pic like i was planning to:
Code:
    $img_src = end(explode("/", $img));
    $imgid = basename($img, ".jpg");
    echo "<a href='http://www.mydomain/id=$imgid'><img src='{$img_src}'/></a>";
} 
?>
And it works exactly like i wanted! Thanks a lot for helping me out
nico-t is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-30-2012, 07:30 AM   #7
Oracle Porn
Affiliate
 
Oracle Porn's Avatar
 
Industry Role:
Join Date: Oct 2002
Location: Icq: 94-399-723
Posts: 24,433
you mind posting the entire edited code?
thanks
__________________


Oracle Porn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-30-2012, 07:31 AM   #8
Oracle Porn
Affiliate
 
Oracle Porn's Avatar
 
Industry Role:
Join Date: Oct 2002
Location: Icq: 94-399-723
Posts: 24,433
Quote:
Originally Posted by seeandsee View Post
Hi, thanks for this code. Can you point me to some good php tutorial site, i have experience in programing (c, c++, basic, even pascal) but i need good site to learn some step by step php code?
I use this site
__________________


Oracle Porn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-30-2012, 07:32 AM   #9
nico-t
emperor of my world
 
Join Date: Aug 2004
Location: nethalands
Posts: 29,903
one thing i noticed. About the above code.

When you have your scriptcode.php in the same folder as the images, the rotator sometimes grabs the .php file too.

When i put the scriptcode.php in a parent folder:
/mysite/script/scriptcode.php
And the images in:
/mysite/script/images/image.jpg

The script looks for the images in /mysite/script/ like it doesn't see the images folder.
I have put the correct image path in the script. Think it has something to do with the explode code?
nico-t is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-30-2012, 08:23 AM   #10
nico-t
emperor of my world
 
Join Date: Aug 2004
Location: nethalands
Posts: 29,903
fixed the above by just adding images dir before the img src output.


Quote:
Originally Posted by Oracle Porn View Post
you mind posting the entire edited code?
thanks
ofcourse, here it is.
script is at:
mysite.com/script/script.php
Images in:
mysite.com/script/images/

Code:
Code:
<?php
define('BASE_DIR', '/home/user/domains/mysite.com/public_html/script/images/'); // Where are your images?
define('IMAGE_LIMIT', 5); // how many images to show?

$files     = glob(BASE_DIR.'*');
$images = Array();

if(empty($files)) {
    die("Hey, dude, there are no files. What happened?");
}

foreach($files as $v) {
    if(is_dir($v)) {
        foreach($files as $v) { // This should be a function which can loop through further sub directories if needed
            //get exif image type, if it's an image append to array
            $images[] = $v;
        }
    } else {
        $images[] = $v;
    }
}

shuffle($images); // Randomise the array
for($i=0;$i<IMAGE_LIMIT;$i++) {
    $img = $images[$i];
    if(empty($img)) {
        break; // Might be best doing a foreach above whilst keeping $i as a loop counter and breaking the loop once you reach the limit
    }
    $img_src = end(explode("/", $img));
    $imgid = basename($img, ".jpg");
    echo "<a href='http://www.mysite.com/id=$imgid'><img src='images/{$img_src}'/></a>";
} 
?>
Takes filename of pic (which is also the url ID) to link every pic to its own ID page.
nico-t is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-30-2012, 09:07 AM   #11
Barry-xlovecam
It's 42
 
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
nvm ..... read the image part

Last edited by Barry-xlovecam; 12-30-2012 at 09:09 AM..
Barry-xlovecam is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-30-2012, 09:54 AM   #12
fitzmulti
I Like Depth Of Field!
 
fitzmulti's Avatar
 
Industry Role:
Join Date: Jan 2003
Location: Las Vegas, NV, USA: 36.12318 N, 115.090219 W
Posts: 14,861
Neat code to have. Thanks!
__________________


www.SexyGirlsCash.com


CONTACT // FITZMULTI AT GMAIL.COM //
{Please include a message so I know you are from GFY! I get too many spam "add requests"!}
fitzmulti is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.