Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2003, 10:32 PM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default In need of a "random image script," that does a bit more..

I've searched through hotscripts.com, but can't seem to find this kind of script.

I'm in need of a PHP, or javascript, random image script that will read all the files in a directory and all directories within that directory for images, then will display a random image upon refresh of the page.

I've found scripts that will read all the images within a directory, but I need this to work similar to that of the Windows XP image screensaver, where it also searches through all the folders within that directory for images.

Here is a PHP random image script, is there possibly a way to modify it to do what I need here?

http://www.hotscripts.com/Detailed/16876.html

Or, maybe there is already a script somewhere that does this.

Thanks if you can help
Reply With Quote
  #2  
Old 02-09-2003, 04:13 PM
ULTIMATESSJ's Avatar
ULTIMATESSJ ULTIMATESSJ is offline
 
Join Date: Nov 2001
Location: Bristol, England
Posts: 315
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

just put this in a php file, you'll know what to do next,won't work on a windows server though

PHP Code:

<?php
# folder from the document_root you want to include and all sub dirs
 
$folder "images";
    function 
createimagearray($newdir){
     global 
$folder,$newarray,$DOCUMENT_ROOT;
     
$dir_subdirs = array();
     
chdir($newdir);

     
$handle opendir($newdir);

        while(
$entry readdir($handle)){
         
$dirtitle str_replace($DOCUMENT_ROOT,"",$newdir);
         
$last4 substr(strtolower($entry),-4);
            if(
is_dir($entry) && $entry != ".." && $entry != "."){
             
$dir_subdirs[] = $entry;
            } elseif(
$entry != ".." && $entry != "." && ($last4 == ".gif" || $last4 == ".jpg" || $last4 == ".png" || $last4 == ".bmp")){
             
$newarray .= "$dirtitle$entry||";
            }
        }
     
sort($dir_subdirs);
           for(
$i=0$i<count($dir_subdirs); $i++){
         
$array createimagearray("$newdir$dir_subdirs[$i]/");
        }
     
closedir($handle);
     return 
$newarray;
    }
 
$array    createimagearray($DOCUMENT_ROOT."/".$folder."/");
 
$array substr($array0,-2);
 
$array explode("||",$array);
    function 
make_seed() {
     list(
$usec$sec) = explode(' 'microtime());
     return (float) 
$sec + ((float) $usec 100000);
    }
 
srand(make_seed());
 
$view $array[rand(0,(count($array))-1)];
 echo 
"<img src=\"$view\">";
?>
tell me if it doesn't work though, cause i want to use it for other things as well, and my localhost isn't working at the moment, plus i'm quite a php n00b, this wasn't made for forum use though, just a seperate script, but i'm sure you can get it to work
Reply With Quote
  #3  
Old 02-09-2003, 11:03 PM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Cool, it works well

You can see what I did with it on my homepage, for the "Anime Capture" thingy.

Basically in a template where you want the image to precisely show, insert this piece of code:

Code:
<script language="javascript" src="randscreen.php"></script>
I just named the file "randscreen.php," ofcourse.

Though, you need to change one line in that script of yours to function with the Javascript.

Change:
PHP Code:
echo "<img src=\"$view\">"
To:
PHP Code:
echo("document.write('<img src=\"$view\"></a>');"); 
And it should work.
Thanks for posting this also Ultimate.
Reply With Quote
  #4  
Old 03-09-2003, 08:12 AM
AmericanWoman AmericanWoman is offline
 
Join Date: Jan 2002
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I get this error message when I try to use that script:

I'm not a Unix guru by any means, so perhaps I'm doing something wrong...but I can't figure out what!

PHP Code:
Warningchdir() [function.chdir]: No such file or directory (errno 2in /usr/local/apache/htdocs/forums/randimage.php on line 7

Warning
opendir(/images/gallery/) [function.opendir]: failed to open dirNo such file or directory in /usr/local/apache/htdocs/forums/randimage.php on line 9

Warning
readdir(): supplied argument is not a valid Directory resource in /usr/local/apache/htdocs/forums/randimage.php on line 11

Warning
closedir(): supplied argument is not a valid Directory resource in /usr/local/apache/htdocs/forums/randimage.php on line 24
document
.write(''); 
Help?
Reply With Quote
  #5  
Old 04-07-2003, 09:33 PM
ULTIMATESSJ's Avatar
ULTIMATESSJ ULTIMATESSJ is offline
 
Join Date: Nov 2001
Location: Bristol, England
Posts: 315
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
03-09-03 at 11:12 AM AmericanWoman said this in Post #4
I get this error message when I try to use that script:

I'm not a Unix guru by any means, so perhaps I'm doing something wrong...but I can't figure out what!

PHP Code:
Warningchdir() [function.chdir]: No such file or directory (errno 2in /usr/local/apache/htdocs/forums/randimage.php on line 7

Warning
opendir(/images/gallery/) [function.opendir]: failed to open dirNo such file or directory in /usr/local/apache/htdocs/forums/randimage.php on line 9

Warning
readdir(): supplied argument is not a valid Directory resource in /usr/local/apache/htdocs/forums/randimage.php on line 11

Warning
closedir(): supplied argument is not a valid Directory resource in /usr/local/apache/htdocs/forums/randimage.php on line 24
document
.write(''); 
Help?
have you got an images folder present in the place where you're running this script
Reply With Quote
  #6  
Old 08-20-2005, 07:10 AM
ambumann ambumann is offline
 
Join Date: Jun 2004
Posts: 86
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice one, any possiblities of having a default image size within this script??
Reply With Quote
  #7  
Old 10-05-2005, 11:21 PM
PennylessZ28 PennylessZ28 is offline
 
Join Date: Mar 2002
Location: North America
Posts: 737
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

that don't work
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 07:09 PM.


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.03921 seconds
  • Memory Usage 2,272KB
  • 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
  • (5)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete