php script gesucht!

Discuss phpwcms here, please do not post support requests, bug reports, or feature requests! Non-phpwcms questions, discussion goes in General Chat!
Post Reply
tikemyson
Posts: 54
Joined: Sat 29. Nov 2003, 02:10
Contact:

php script gesucht!

Post by tikemyson »

hallo.
ich möchte für einen banner folgendes random-script benutzen:

Code: Select all

<?php  
// print a random image.  Don't forget ending slash!
// setting $type to 'all' will return all images.

print getRandomImage('headerpics/');     // Bildordner 

function getRandomImage($dir,$type='random')
{ 
global $errors,$seed; 

  if (is_dir($dir)) {  

  $fd = opendir($dir);  
  $images = array(); 

      while (($part = @readdir($fd)) == true) {  

          if ( eregi("(gif|jpg|png|jpeg)$",$part) ) {
              $images[] = $part; 
          } 
      } 

    // adding this in case you want to return the image array
    if ($type == 'all') return $images;

    if ($seed !== true) {
      mt_srand ((double) microtime() * 1000000);
      $seed = true;
    }
      
      $key = mt_rand (0,sizeof($images)-1); 

     echo " [color=red]<a href=\"$ziel\"><img src=\"$dir/$images[$key]\" ></img></a>";[/color]// weiß nicht genau ob das so funktioniert??


  } else { 
      $errors[] = $dir.' is not a directory'; 
      return false; 
  } 
} 

?> 
 


So...

was mir hier allerdings fehlt, ist ein Link zur entsprechenden Site.

Ich habe mir das ganze etwa so vorgestellt:

if $images=="abcde.jpg" the $ziel := "http://www.abcde.de"
if $images=="xyz.jpg" the $ziel := "http://www.xyz.de"
if $images=="kkk.jpg" the $ziel := "http://www.kkk.de"

Kann mir jmd weiterhelfen?

Danke.

Ausserdem bräuchte ich dann noch einen Tip, wie man bei einem Link den Rahmen wegbekommt!

Vielen Dank
------------------
have phun!
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

zu 2tem:

border="0"
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
jmeyknecht
Posts: 112
Joined: Sun 11. Jan 2004, 23:13
Location: Merseburg, Germany
Contact:

Post by jmeyknecht »

wie wärs mit dem apbspeichern der quelle des bildes und der zu verlinkenden URL in einem 2-dimensionalem Array?

HTH

edit:

in deinem fall wird es wohl auch ein einfaches

Code: Select all

$ziel = "http://".filename($images[$key].".de"; //oder so ähnlich
tun
cguenther
Posts: 111
Joined: Sun 11. Jan 2004, 12:41
Location: Halle, Germany
Contact:

Post by cguenther »

jmeyknecht wrote:

Code: Select all

$ziel = "http://".filename($images[$key].".de"; //oder so ähnlich
das hätte lediglich den nachteil, dass die TLD der Domain nicht im Bild codiert wäre. Dem müsste, wenn es nicht nur .de-Domains sind noch Rechnung getragen werden.
tikemyson
Posts: 54
Joined: Sat 29. Nov 2003, 02:10
Contact:

Post by tikemyson »

hallo...

ich habe jetzt folgendermassen gecoded!

Code: Select all

<?php  

// print a random image.  Don't forget ending slash!
// setting $type to 'all' will return all images.
print getRandomImage('Mallorca_Abschlussfahrt_04/'); 

function getRandomImage($dir,$type='random')
{ 
global $errors,$seed,$firmenurl; 

  if (is_dir($dir)) {  

  $fd = opendir($dir);  
  $images = array(); 

      while (($part = @readdir($fd)) == true) {  

          if ( eregi("(gif|jpg|png|jpeg)$",$part) ) {
              $images[] = $part; 
          } 
      } 

    // adding this in case you want to return the image array
    if ($type == 'all') return $images;

    if ($seed !== true) {
      mt_srand ((double) microtime() * 1000000);
      $seed = true;
    }
      
      $key = mt_rand (0,sizeof($images)-1); 
      echo "$images[$key]";
       echo "$firmenurl<br><br><br><br><br><br><br><br><br><br><br><br><br>";

       if ($images[$key] == 'thomaswalter.jpg') {
												$firmennurl="http://www.thomaswalter.de";
												}
	 
  		if ($images[$key] == 'groupthink.jpg') {
												$firmennurl="http://www.groupthink.de";
											   }
														 else
															{
																$firmennurl="http://www.groupthink.de";
															};
		
		

     echo " <a href=\"$firmenurl\" target=\" _blank\"> <img src=\"$dir/$images[$key]\" ></img></a>";
     

  } else { 
      $errors[] = $dir.' is not a directory'; 
      return false; 
  } 


} 

?> 
 

Komischerweise funktioniert die Sache im ie nicht...werde immer zu svthalexweiler.de geleitet.

Im Mozilla wird der Link (klick auf das Bild) immer das eigene skript wieder refreshed.! Komisch.





http://www.svthalexweiler.de/sponsorrandom.php

weiß jmd rat?

danke
------------------
have phun!
tikemyson
Posts: 54
Joined: Sat 29. Nov 2003, 02:10
Contact:

Post by tikemyson »

noch nebenbei....

in dem, ordner 'Mallorca_Abschlussfahrt_04' befinden sich 3 bilder.

die variable images[key] gibt den namen der bilddatei als string in der datei aus!
------------------
have phun!
Neelix
Posts: 80
Joined: Wed 29. Sep 2004, 12:06
Location: España

Post by Neelix »

tikemyson wrote:

Code: Select all

 ...
      if ($images[$key] == 'thomaswalter.jpg')
     {
        $firmennurl="http://www.thomaswalter.de";
     }
      if ($images[$key] == 'groupthink.jpg')
     {
	$firmennurl="http://www.groupthink.de";
     }
   else
   {
    $firmennurl="http://www.groupthink.de";
    }
...
 
:idea: Ich denke du willst so was:
...
switch ($images[$key] )
{
case 'thomaswalter.jpg':
$firmennurl="http://www.thomaswalter.de";
break;
case 'groupthink.jpg':
$firmennurl="http://www.groupthink.de";
break;
default:
$firmennurl="http://www.xvz.de"; //!!!
}
...
oder?
------------
Nachtrag: mit meinem Test :D - zeigt die URL zur Kontrolle mit an:

Code: Select all

	switch ($images[$key])
	{
		case 'next.gif':  $firmennurl="http://www.phpwcms.de";  break;
		case 'colorchart.gif': $firmennurl="http://www.php.net"; break;
		default:
				$firmennurl="http://www.web.de";
	}
    echo '<a href="'.$firmennurl.'" target="_blank"><img src="'.$dir.'/'.$images[$key].'">'.$firmennurl.'</a';
works fine ...
Last edited by Neelix on Mon 25. Oct 2004, 15:08, edited 1 time in total.
Erfahrung ist das, was man besitzt, kurz nach dem es gebraucht wurde.
Warning: I have no foggiest idea of English/German, but I do
-ha{p}{p}y day/night/dia/noche-
tikemyson
Posts: 54
Joined: Sat 29. Nov 2003, 02:10
Contact:

Post by tikemyson »

werde es testen und berichten...!

Danke vorerst mal!
------------------
have phun!
tikemyson
Posts: 54
Joined: Sat 29. Nov 2003, 02:10
Contact:

Danke!

Post by tikemyson »

YOU GOT THE FLAG!

vielen dank!
Funzt hervorlich!
------------------
have phun!
Post Reply