vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   In need of a "random image script," that does a bit more.. (https://vborg.vbsupport.ru/showthread.php?t=48714)

Velocd 02-08-2003 10:32 PM

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 ;)

ULTIMATESSJ 02-09-2003 04:13 PM

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

Velocd 02-09-2003 11:03 PM

Cool, it works well :p

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. ;)

AmericanWoman 03-09-2003 08:12 AM

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?

ULTIMATESSJ 04-07-2003 09:33 PM

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

ambumann 08-20-2005 07:10 AM

Nice one, any possiblities of having a default image size within this script??

PennylessZ28 10-05-2005 11:21 PM

that don't work


All times are GMT. The time now is 02:29 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01109 seconds
  • Memory Usage 1,778KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (5)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete