Created
January 26, 2019 17:09
-
-
Save radarin/999c5535110136dcb98ab23d59c4122e to your computer and use it in GitHub Desktop.
Zufallsbild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Allgemeine PHP-Variante | |
add_shortcode( 'randompic', 'rad_randompic' ); | |
$vn = "./static-img/randompic"; | |
$html_vn = "static-img/randompic/"; | |
$barray = array(1,2,3,4,5); | |
$verzeichnis = opendir($vn); | |
while($file = readdir($verzeichnis)) { | |
$s = @getimagesize($vn."/".$file); | |
if(in_array($s[2], $barray)) | |
$auswahl[] = $file; | |
} | |
mt_srand((double)microtime()*1000000); | |
$number = mt_rand(0,count($auswahl)-1); | |
$ausgabe = "<img src='".$html_vn.$auswahl[$number]."'>"; | |
return $ausgabe; | |
?> | |
<?php | |
// Variante mit Funktion und Shortcode für Wordpress | |
add_shortcode( 'randompic', 'rad_randompic' ); | |
function rad_randompic() { | |
$vn = "./static-img/randompic"; | |
$html_vn = "static-img/randompic/"; | |
$barray = array(1,2,3,4,5); | |
$verzeichnis = opendir($vn); | |
while($file = readdir($verzeichnis)) { | |
$s = @getimagesize($vn."/".$file); | |
if(in_array($s[2], $barray)) | |
$auswahl[] = $file; | |
} | |
mt_srand((double)microtime()*1000000); | |
$number = mt_rand(0,count($auswahl)-1); | |
$ausgabe = "<img src='".$html_vn.$auswahl[$number]."'>"; | |
return $ausgabe; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment