.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
Re: a different sig each time
Old
  (#21)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: a different sig each time - 12-05-2004

oh yeah, I'm interested as well

that's teh way I'm learning PHP: by reading at other ppl's code...



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: a different sig each time
Old
  (#22)
[NvT]_KaszpiR_
Member
 
[NvT]_KaszpiR_'s Avatar
 
Status: Offline
Posts: 322
Join Date: Apr 2004
Default Re: a different sig each time - 12-05-2004

once i was using crontab
then i used php genrated image
then the .php links were forbidden because it could return dangerouns output so i changed it to writ the .jpg file a diff file (well more like crontab script in fact)

now i use static jpg cause i got used to it - easier to find my own posts
  
Reply With Quote
Re: a different sig each time
Old
  (#23)
FrostyCoolSlug
Member
 
FrostyCoolSlug's Avatar
 
Status: Offline
Posts: 318
Join Date: Mar 2004
Default Re: a different sig each time - 12-05-2004

ok, here we go then
This script is much longer than the others, but does what its told

PHP Code:
<?php

$filepath 
"images/";
$extentions = Array("PNG""JPG""GIF");

// Open the Directory and clear the files array (JIC)
$handle = @opendir($filepath) or die("");
$files = Array();

// Loop through all the files in the directory
while (false !== ($file readdir($handle))) {
    
// Make sure they are not directories
    
if (!is_dir($file)) {
        foreach (
$extentions as $m00) {
            
// Case insencitive comparison of file extention and
            // Allowed extention
            
if (strcasecmp(getext($file), $m00)) {
                
// Positive Match, add the file to the array
                
$files[] = $file;
                
// Jump out the foreach and tell the while to continue
                
continue 2;
            } 
        } 
    } 

// Make sure there are some files..
if (!count($files)) {
    
// No Valid files were found, kill self.
    
return;
} else {
    
// Choose a random image (the keys are numbers, so can rand them)
    // Use count() -1 because count() starts at 1 and not 0 
    
$img rand(0count($files) - 1);

// Output the file.
readfile($filepath $files[$img]); 

// Function used for fetching extentions..
function getext($file)
{
    
$file explode("."$file);
    return 
$file[count($file) - 1];


?>
I've commented it well, so you know what i'm doing. I've tested it, and know it works

If you have any questions, gimme a shout


=====
Craig "FrostyCoolSlug" McLure
Network Administrator of the ChatSpike IRC Network

Last edited by FrostyCoolSlug; 12-05-2004 at 18:50..
  
Reply With Quote
Re: a different sig each time
Old
  (#24)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: a different sig each time - 12-05-2004

hehe thanks

I've made it a lil bit shorter

don't forget to close the directory handle in your code btw...
Code:
<?php
 
$handle = opendir (getcwd ()) or die ();
$files = Array ();
$file_count = 0;
 
// loop through all the files in the directory
while (($file = readdir ($handle)) !== false)
{
   if (is_dir ($file))
	  continue; // discard directories
 
   $ext = strstr ($file, "."); // get the file extension
 
   // is this file of one of the allowed extensions ?
   if ((strcasecmp ($ext, ".png") == 0)
	   || (strcasecmp ($ext, ".jpeg") == 0)
	   || (strcasecmp ($ext, ".gif") == 0))
   {
	  $files[$file_count] = $file; // yes it is, add the file to the array
	  $file_count++; // we know now one image more
   }
}
 
closedir ($handle); // finished, don't forget to close directory handle
 
// did we find no image ?
if ($file_count == 0)
   return; // if so, don't output anything at all.
 
// output a random image file among those in the array
readfile ($files[rand (0, $file_count - 1)]);
 
?>



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."

Last edited by Pierre-Marie Baty; 12-05-2004 at 19:16..
  
Reply With Quote
Re: a different sig each time
Old
  (#25)
SoUlFaThEr
Moderator
 
SoUlFaThEr's Avatar
 
Status: Offline
Posts: 860
Join Date: Mar 2004
Default Re: a different sig each time - 12-05-2004

how in the world could a simple Joe like me get this one going? i like that kind of stuff!


  
Reply With Quote
Re: a different sig each time
Old
  (#26)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: a different sig each time - 12-05-2004

Well, just copy what's inside the code tags and paste it in your notepad, then save the file and name it "sig.php" or whatever. Then upload it to your server in the directory where you put your signatures, and instead of using [ img]http://soulfathermaps.de/images/mysig.jpg[ /img] use [ img]http://soulfathermaps.de/images/sig.php[ /img]
That should be enough
Ensure the directory where your sig is has read access allowed to anybody.



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: a different sig each time
Old
  (#27)
SoUlFaThEr
Moderator
 
SoUlFaThEr's Avatar
 
Status: Offline
Posts: 860
Join Date: Mar 2004
Default Re: a different sig each time - 12-05-2004

sounds real easy

and how do i make it select 4 pics designed just for this purpose? and not the whole bank of pics?



Last edited by SoUlFaThEr; 12-05-2004 at 23:47..
  
Reply With Quote
Re: a different sig each time
Old
  (#28)
Huntkillaz
Member
 
Huntkillaz's Avatar
 
Status: Offline
Posts: 594
Join Date: Mar 2004
Location: Middle Earth (New Zealand)
Default Re: a different sig each time - 13-05-2004

to my understanding (php is one of my things in the the things to learn list )

if u upload the 4 photo's\images and the sig in the same folder to the server
and link upto that sig.php script it will automatically choose from that 4 becoz there is no other in that folder


●_•
  
Reply With Quote
Re: a different sig each time
Old
  (#29)
FrostyCoolSlug
Member
 
FrostyCoolSlug's Avatar
 
Status: Offline
Posts: 318
Join Date: Mar 2004
Default Re: a different sig each time - 13-05-2004

Quote:
$ext = strstr ($file, "."); // get the file extension
You gotta be careful with this, some people like adding extra .'s to their filenames (god knows why), so if someone had a file called my.pic.jpg, $ext would be pic.jpg, which wont work in comparison with the others.

Quote:
while (($file = readdir ($handle)) !== false)
I'm not sure why that was changed, i used what was recommended @ php.net as the 'right' way to do it.

Mine was designed to be more customisable, rather than 'just work', so you could select the folder easily, and simple add , "ext" to add an extention to the list..

What i've done here, is taken the speed of yours, and the customisability of mine, and combined them, and got the following :p

PHP Code:
<?php

$target 
getcwd() . "/images";
$extentions = Array("PNG""JPG""GIF");
$files = Array();
$file_count 0;

$handle opendir($target) or die ();
while ((
$file readdir($handle)) !== false) {
    if (
is_dir ($file))
        continue;
    
$tmp explode("."$file);
    
$ext $file[count($file) - 1];
    unset(
$tmp);
    foreach (
$extentions as $m00) {
        if (
strcasecmp($ext$m00)) {
            
$files[$file_count++] = $file;
            continue 
2;
        } 
    } 


closedir ($handle);

if (!
$file_count)
    return;

readfile ($files[rand (0$file_count) -1]);

?>
Its not commented, but you should know what it does by now


=====
Craig "FrostyCoolSlug" McLure
Network Administrator of the ChatSpike IRC Network

Last edited by FrostyCoolSlug; 13-05-2004 at 04:46.. Reason: Mess up (Thanks for pointing it out PM)
  
Reply With Quote
Re: a different sig each time
Old
  (#30)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: a different sig each time - 13-05-2004

@Frosty: About the "rand (0, $file_count - 1)", I suppose the array indexing works just like in C ?
Let's say we have an array of 3 elements (hence $file_count = 3)
we have
array[0] -> first element
array[1] -> second element
array[2] -> third element (and no array[3], which is out of bounds)
is that right ?
so if I want to pick a random number between 0 and 2 inclusively, I call rand (0, $file_list - 1)... well that's how I see things, but you know PHP better than me so... ???

@SF: with this script you have to arrange your pics into subdirectories, because it takes the whole image list.
If you want a script that would output only a selected set of images randomly, you can write something like this:
Code:
<?php 

$files = Array("image1.gif", "image2.jpeg", "image3.png"); // list of files
$file_count = 3; // number of files to choose from

// take one file randomly among the list and send it away
readfile ($files[rand (0, $file_count - 1)]);

?>



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com