ERLEDIGT
NEIN
NEIN
ANTWORTEN
4
4
ZUGRIFFE
279
279
EMPFEHLEN
-
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($dir, 0, $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 = $e[ count($e)-1 ];
if( is_file($dir.'/'.$file) && in_array($ext, $allowed_file_extensions) ) {
$files[] = $dir.'/'.$file;
}
}
return $files;
}
$files = getFiles('image/gate');
$rand = mt_rand(0, count($files)-1);
$rand2 = mt_rand(0, count($files)-1);
$rand3 = mt_rand(0, count($files)-1);
$rand4 = mt_rand(0, count($files)-1);
$rand5 = mt_rand(0, count($files)-1);
$rand6 = mt_rand(0, count($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>
';
-
27.04.10 23:31 #2
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(6, 0, count($files)-1);
?>
-
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($dir, 0, $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 = $e[ count($e)-1 ];
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(6, 0, count($files)-1);
}
$files = getFiles('image/gate');
$rand = mt_rand(0, count($files)-1);
$rand2 = mt_rand(0, count($files)-1);
$rand3 = mt_rand(0, count($files)-1);
$rand4 = mt_rand(0, count($files)-1);
$rand5 = mt_rand(0, count($files)-1);
$rand6 = mt_rand(0, count($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)
-
28.04.10 00:41 #4
Das geht auch noch einfacher.
Übrigens, mit glob() kannst du das Auslesen des Verzeichnisses noch weiter vereinfachen.PHP-Code:<?php
function getEntries($array, $count)
{
$entries = array();
$entries = array_rand($array, $count);
return $entries;
}
$array = range(1,100);
var_dump(getEntries($array, 6));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"
-
Ich wollte eigentlich auch helfen.
Aber so ohne Satzzeichen versteh ich diesen Satz auch nach 3 maligem Durchlesen nicht.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---------------------------------------------------------------------------------------------------
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
-
Bildwechsel mit PHP
Von mediaroad im Forum Javascript & AjaxAntworten: 10Letzter Beitrag: 05.08.08, 10:38 -
Bildwechsel nur mit CSS
Von purpur im Forum CSSAntworten: 9Letzter Beitrag: 03.07.08, 21:34 -
Bildwechsel in SWT
Von samma im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 0Letzter Beitrag: 03.04.07, 23:14 -
Bildwechsel...
Von jackobo im Forum Javascript & AjaxAntworten: 1Letzter Beitrag: 10.11.05, 01:44 -
Bildwechsel
Von bittegutfinden im Forum Javascript & AjaxAntworten: 5Letzter Beitrag: 20.03.03, 12:12





Zitieren

Login






[PHP][Snippet] Array zu XML konvertieren