![]() |
![]() |
![]() |
||||
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. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
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? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
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.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Affiliate
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}'/>"; } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 | |
Check SIG!
Industry Role:
Join Date: Mar 2006
Location: Europe (Skype: gojkoas)
Posts: 50,945
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
So fuckin' bored
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 | |
emperor of my world
Join Date: Aug 2004
Location: nethalands
Posts: 29,903
|
Quote:
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>"; } ?> ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Affiliate
Industry Role:
Join Date: Oct 2002
Location: Icq: 94-399-723
Posts: 24,433
|
you mind posting the entire edited code?
![]() thanks |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
Affiliate
Industry Role:
Join Date: Oct 2002
Location: Icq: 94-399-723
Posts: 24,433
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
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? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
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.
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>"; } ?> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
It's 42
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
|
nvm ..... read the image part
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
I Like Depth Of Field!
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"!} |
![]() |
![]() ![]() ![]() ![]() ![]() |