tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
4
ZUGRIFFE
279
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Deadfish Deadfish ist offline Mitglied Silber
    Registriert seit
    Apr 2010
    Beiträge
    51
    Hallo ich hab ein kleinen Script der auch Funktioniert nur mein Problem ist halt das es ja 6 Bilder sind die angezeigt werden das ist ja okey wolte es ja so nur ich möchte gerne das die Bilder nicht doppelt vorkommen also das es immer 6 verschiedene sind wäre das mit dem Script machbar

    PHP-Code:
    <?php
    function getFiles($dir)
    {
    static 
    $files;

    $allowed_file_extensions = array();
    $allowed_file_extensions[] = 'gif';
    $allowed_file_extensions[] = 'bmp';
    $allowed_file_extensions[] = 'jpg';
    $allowed_file_extensions[] = 'jpeg';
    $allowed_file_extensions[] = 'png';


    $len strlen($dir);
    if(
    $dir{$len-1} == '/')
    $dir substr($dir0$len-1);

    if(!
    is_dir($dir))
    return 
    false;

    $open = @opendir($dir);

    if(!
    $open)
    return 
    false;

    while(
    $file readdir($open)) {
    if(
    $file == "." || $file == "..")
    continue;

    if(
    preg_match('/(.*)_t([0-9]*).jpg/i'$file))
    continue;

    if(
    is_dir($dir.'/'.$file)) {
    getFiles($dir.'/'.$file);
    }

    $e explode('.'$file);
    $ext $ecount($e)-];

    if( 
    is_file($dir.'/'.$file) && in_array($ext$allowed_file_extensions) ) {
    $files[] = $dir.'/'.$file;
    }
    }

    return 
    $files;
    }


    $files getFiles('image/gate');
    $rand mt_rand(0count($files)-1);
    $rand2 mt_rand(0count($files)-1);
    $rand3 mt_rand(0count($files)-1);
    $rand4 mt_rand(0count($files)-1);
    $rand5 mt_rand(0count($files)-1);
    $rand6 mt_rand(0count($files)-1);
    ?>
    <script type="text/javascript">
    function show_pic(file_name){

    width = 42;
    height = 42;

    var p = "menubar=no,location=no,toolbar=no,status=no, resizable=yes,scrollbars=yes";
    var x = (screen.availWidth - width - 5) / 2;
    var y = (screen.availHeight - height - 5) / 2;
    if (x> && y>){
    p = "width="+width+",height="+height+",left="+x+",top= "+y+","+p;
    }

    var Fenster = window.open(file_name, 'Grossansicht', p);
    Fenster.focus();
    }
    </script>
    <?
    echo '
    <a onclick="showpic(\'thumb_'
    $files$rand ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand ] .'" width="32" height="32" border="0" /></a>
    <a onClick="showpic(\'thumb_'
    $files$rand2 ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand2 ] .'" width="32" height="32" border="0" /></a>
    <a onclick="showpic(\'thumb_'
    $files$rand3 ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand3 ] .'" width="32" height="32" border="0" /></a>
    <a onclick="showpic(\'thumb_'
    $files$rand4 ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand4 ] .'" width="32" height="32" border="0" /></a>
    <a onclick="showpic(\'thumb_'
    $files$rand5 ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand5 ] .'" width="32" height="32" border="0" /></a>
    <a onclick="showpic(\'thumb_'
    $files$rand6 ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand6 ] .'" width="32" height="32" border="0" /></a>
    '
    ;
     

  2. #2
    Avatar von tobee
    tobee tobee ist offline Grolba.com media
    Registriert seit
    Jul 2005
    Ort
    Karlsruhe
    Beiträge
    1.700
    Blog-Einträge
    131
    Die folgende Funktion gibt dir ein Array zurück mit "einmaligen" Zahlen
    PHP-Code:
    <?php
    function random($n$min 0$max null) {
        if(
    $max === null) {
            
    $max getrandmax();
        }
        
    $array range($min$max);
        
    $return = array();
        
    $keys array_rand($array$n);
        foreach(
    $keys as $key) {
            
    $return[] = $array[$key];
        }
        return 
    $return;
    }

    random(60count($files)-1);
    ?>
     

  3. #3
    Deadfish Deadfish ist offline Mitglied Silber
    Registriert seit
    Apr 2010
    Beiträge
    51
    Hab es jetzt so eingebaut es Funktioniert so zu 90% also es geht aber net immer

    PHP-Code:
    <?php
    function getFiles($dir)
    {
    static 
    $files;

    $allowed_file_extensions = array();
    $allowed_file_extensions[] = 'gif';
    $allowed_file_extensions[] = 'bmp';
    $allowed_file_extensions[] = 'jpg';
    $allowed_file_extensions[] = 'jpeg';
    $allowed_file_extensions[] = 'png';


    $len strlen($dir);
    if(
    $dir{$len-1} == '/')
    $dir substr($dir0$len-1);

    if(!
    is_dir($dir))
    return 
    false;

    $open = @opendir($dir);

    if(!
    $open)
    return 
    false;

    while(
    $file readdir($open)) {
    if(
    $file == "." || $file == "..")
    continue;

    if(
    preg_match('/(.*)_t([0-9]*).jpg/i'$file))
    continue;


    if(
    is_dir($dir.'/'.$file)) {
    getFiles($dir.'/'.$file);
    }

    $e explode('.'$file);
    $ext $ecount($e)-];

    if( 
    is_file($dir.'/'.$file) && in_array($ext$allowed_file_extensions) ) {
    $files[] = $dir.'/'.$file;
    }
    }

    return 
    $files;
    function 
    random($n$min 0$max null) {
        if(
    $max === null) {
            
    $max getrandmax();
        }
        
    $array range($min$max);
        
    $return = array();
        
    $keys array_rand($array$n);
        foreach(
    $keys as $key) {
            
    $return[] = $array[$key];
        }
        return 
    $return;
    }

    random(60count($files)-1);
    }



    $files getFiles('image/gate');
    $rand mt_rand(0count($files)-1);
    $rand2 mt_rand(0count($files)-1);
    $rand3 mt_rand(0count($files)-1);
    $rand4 mt_rand(0count($files)-1);
    $rand5 mt_rand(0count($files)-1);
    $rand6 mt_rand(0count($files)-1);
    ?>
    <script type="text/javascript">
    function show_pic(file_name){

    width = 42;
    height = 42;

    var p = "menubar=no,location=no,toolbar=no,status=no, resizable=yes,scrollbars=yes";
    var x = (screen.availWidth - width - 5) / 2;
    var y = (screen.availHeight - height - 5) / 2;
    if (x> && y>){
    p = "width="+width+",height="+height+",left="+x+",top= "+y+","+p;
    }

    var Fenster = window.open(file_name, 'Grossansicht', p);
    Fenster.focus();
    }
    </script>
    <?
    echo '
    <a onclick="showpic(\'thumb_'
    $files$rand ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand ] .'" width="32" height="32" border="0" /></a>
    <a onClick="showpic(\'thumb_'
    $files$rand2 ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand2 ] .'" width="32" height="32" border="0" /></a>
    <a onclick="showpic(\'thumb_'
    $files$rand3 ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand3 ] .'" width="32" height="32" border="0" /></a>
    <a onclick="showpic(\'thumb_'
    $files$rand4 ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand4 ] .'" width="32" height="32" border="0" /></a>
    <a onclick="showpic(\'thumb_'
    $files$rand5 ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand5 ] .'" width="32" height="32" border="0" /></a>
    <a onclick="showpic(\'thumb_'
    $files$rand6 ] .'\');"><img src="http://www.tutorials.de/forum/'$files$rand6 ] .'" width="32" height="32" border="0" /></a>
    '
    ;
    Geändert von Deadfish (28.04.10 um 00:01 Uhr)
     

  4. #4
    Avatar von Flex
    Flex Flex ist offline (aka Felix Jacobi)
    tutorials.de Moderator
    Registriert seit
    Nov 2001
    Ort
    Wuppertal
    Beiträge
    5.295
    Blog-Einträge
    65
    Das geht auch noch einfacher.

    PHP-Code:
    <?php

    function getEntries($array$count)
    {
        
    $entries = array();
        
    $entries array_rand($array$count);
        
        return 
    $entries;
    }

    $array range(1,100);
    var_dump(getEntries($array6));
    Übrigens, mit glob() kannst du das Auslesen des Verzeichnisses noch weiter vereinfachen.
     
    KIDS Kinderbetreuungsdienst
    Xing

    "When you play the game of thrones, you win or you die. There is no middle ground."
    by Cersei Lannister in "A Game Of Thrones"

  5. #5
    Avatar von Yaslaw
    Yaslaw Yaslaw ist offline n/a
    tutorials.de Moderator
    Registriert seit
    Dec 2007
    Ort
    Winterthur(CH)
    Beiträge
    5.205
    Ich wollte eigentlich auch helfen.
    Bildwechsel
    Hallo ich hab ein kleinen Script der auch Funktioniert nur mein Problem ist halt das es ja 6 Bilder sind die angezeigt werden das ist ja okey wolte es ja so nur ich möchte gerne das die Bilder nicht doppelt vorkommen also das es immer 6 verschiedene sind wäre das mit dem Script machbar
    Aber so ohne Satzzeichen versteh ich diesen Satz auch nach 3 maligem Durchlesen nicht.
     
    ---------------------------------------------------------------------------------------------------
    item: Ich habe es mir aus gesundheitlichen Gründen abgewöhnt unformatierten Code zu lesen (Auch SQL-Statements kann man formatieren!)
    item: Tutorial: [PHP][MySQL] Debug Queries
    item: Schreibt mir keine PN mit Fragen die im Forum beantwortet werden können - ich mache kein persönliches coaching
    item: Bitte zur besseren Lesbarkeit PHP-Code in [PHP]...[/PHP], SQL in [SQL]...[/SQL], Visual Basic in [VB]...[/VB] etc. schreiben

Ähnliche Themen

  1. Bildwechsel mit PHP
    Von mediaroad im Forum Javascript & Ajax
    Antworten: 10
    Letzter Beitrag: 05.08.08, 10:38
  2. Bildwechsel nur mit CSS
    Von purpur im Forum CSS
    Antworten: 9
    Letzter Beitrag: 03.07.08, 21:34
  3. Bildwechsel in SWT
    Von samma im Forum Swing, Java2D/3D, SWT, JFace
    Antworten: 0
    Letzter Beitrag: 03.04.07, 23:14
  4. Bildwechsel...
    Von jackobo im Forum Javascript & Ajax
    Antworten: 1
    Letzter Beitrag: 10.11.05, 01:44
  5. Bildwechsel
    Von bittegutfinden im Forum Javascript & Ajax
    Antworten: 5
    Letzter Beitrag: 20.03.03, 12:12