Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-26-2012, 06:21 PM
dsantana dsantana is offline
 
Join Date: Dec 2011
Posts: 67
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Random Image Forum Side Block?

I'm looking for code that will go to a designated directory "/images/ads/sideblock" and grab like 4 or 5 images and place them randomly there.

I found this code and tried to use it as php on a sideblock but I got an error.
I'm not a codr so I though I'd ask you guys that are...
Any help would be awesome...
Thanks...

Code:
<?php
  // Configuration
  $image_path = "";
  $types = array(
    "GIF" => "image/gif",
    "JPG" => "image/jpg",
    "PNG" => "image/png");

  // Directory scan
  $file_list = array();
  $image_path = realpath(trim($image_path) != "" ? $image_path : ".") . "/";
  if ($image_path !== false && is_dir($image_path) && $handle = @opendir($image_path))
  {
    while (($file = readdir($handle)) !== false)
    {
      if (is_file($image_path . $file))
      {
        $file_extension = strtoupper(substr(strrchr($file, "."), 1));
        if (isset($types[$file_extension]))
        {
          $file_list[] = array(
            "filename" => $image_path . $file,
            "mimetype" => $types[$file_extension]);
        }
      }
    }
  }

  // Output
  if (sizeof($file_list) > 0)
  {
    shuffle($file_list);
    header("Content-Type: " . $file_list[0]["mimetype"]);
    header("Content-Length: " . @filesize($file_list[0]["filename"]));
    @readfile($file_list[0]["filename"]);
  }
  else
  {
    die("No images found.");
  }
?>
Reply With Quote
  #2  
Old 06-28-2012, 02:54 AM
DivisionByZero's Avatar
DivisionByZero DivisionByZero is offline
 
Join Date: Dec 2002
Location: South Bend, Indiana
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

first, are the files in this directory named in any specific order? (i.e.: img_1.jpg, img_2..)?
Reply With Quote
  #3  
Old 06-28-2012, 06:22 AM
setishock setishock is offline
 
Join Date: Feb 2008
Location: Houma, La.
Posts: 1,177
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<a href="http://www.alistapart.com/articles/randomizer/" target="_blank">http://www.alistapart.com/articles/randomizer/</a>
The link to the code is near the bottom. Just copy and paste to notepad and save as rotate. php
Make a folder in your ftp and note the path to get to it. Drop your ads in there. Drop a copy of the rotate.php file in there with them.
From the block setup select html. Put the path to the rotate.php file in as the code and save.
Now every time you refresh the page from the browser or leave and come back to the page with the blocks, the rotate.php gets called. It selects a pic at random and displays it.
If you want to show different ads in different blocks you'll have to make more than one folder with your ads in them. Put the rotate.php in each folder and call for them from the different block setups. Otherwise if you call for the same rotate.php file from different blocks they all would show the same ad at the same time.
I would say go look at my site to see it in action but alas animeappeal is no more thanks to crappy hosting.
Reply With Quote
  #4  
Old 06-28-2012, 03:16 PM
dsantana dsantana is offline
 
Join Date: Dec 2011
Posts: 67
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by DivisionByZero View Post
first, are the files in this directory named in any specific order? (i.e.: img_1.jpg, img_2..)?
No they're not

--------------- Added [DATE]1340900369[/DATE] at [TIME]1340900369[/TIME] ---------------

Quote:
Originally Posted by setishock View Post
http://www.alistapart.com/articles/randomizer/
The link to the code is near the bottom. Just copy and paste to notepad and save as rotate. php
Make a folder in your ftp and note the path to get to it. Drop your ads in there. Drop a copy of the rotate.php file in there with them.
From the block setup select html. Put the path to the rotate.php file in as the code and save.
Now every time you refresh the page from the browser or leave and come back to the page with the blocks, the rotate.php gets called. It selects a pic at random and displays it.
If you want to show different ads in different blocks you'll have to make more than one folder with your ads in them. Put the rotate.php in each folder and call for them from the different block setups. Otherwise if you call for the same rotate.php file from different blocks they all would show the same ad at the same time.
I would say go look at my site to see it in action but alas animeappeal is no more thanks to crappy hosting.
Will that allow multiple ads as pictured? One on top of the other?
Reply With Quote
  #5  
Old 06-28-2012, 08:56 PM
setishock setishock is offline
 
Join Date: Feb 2008
Location: Houma, La.
Posts: 1,177
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I had 2 stacked in one block at one time. The block will expand vertically to hold what you cram in there. They all have to be the same width though.
I had the code stacked something like this:
url blah blah blah /br
url blah blah blah

Not real complicated.
Reply With Quote
  #6  
Old 06-28-2012, 10:00 PM
dsantana dsantana is offline
 
Join Date: Dec 2011
Posts: 67
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by setishock View Post
I had 2 stacked in one block at one time. The block will expand vertically to hold what you cram in there. They all have to be the same width though.
I had the code stacked something like this:
url blah blah blah /br
url blah blah blah

Not real complicated.
If I have 10 images and want to have 5 at a time in there randomly and do it that way I could have duplicate images correct?
Reply With Quote
  #7  
Old 06-29-2012, 11:41 PM
setishock setishock is offline
 
Join Date: Feb 2008
Location: Houma, La.
Posts: 1,177
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Say you have 100 ad pics. Make five folders and drop 20 pics in each along with the rotate.php file.
In the sidebar block setting choose html. Using the path to each one of the folders you get this:
url path to folder 1 rotate.php
url path to folder 2 rotate.php

And so on till you have 5 url's stacked. Click save. That should take care of it. You have to have separate url's to separate folders or you get dups.
Reply With Quote
Благодарность от:
DetroitYES
  #8  
Old 08-03-2012, 05:22 PM
pyes pyes is offline
 
Join Date: Mar 2012
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

great info guys....ty. works like a charm

Is there any way to hyper link the banners so people can click on them?
Reply With Quote
  #9  
Old 08-03-2012, 06:18 PM
DetroitYES's Avatar
DetroitYES DetroitYES is offline
 
Join Date: Mar 2009
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by setishock View Post
Say you have 100 ad pics. Make five folders and drop 20 pics in each along with the rotate.php file.
In the sidebar block setting choose html. Using the path to each one of the folders you get this:
url path to folder 1 rotate.php
url path to folder 2 rotate.php

And so on till you have 5 url's stacked. Click save. That should take care of it. You have to have separate url's to separate folders or you get dups.
Alternatively, he could remove the item from the array with unset() once it was used but this is probably easier if he isn't code savvy...
Reply With Quote
Reply


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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:38 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05823 seconds
  • Memory Usage 2,252KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (1)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete