We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

fris on 02/23/08


Tagged

random images files includes


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

Wiederkehr
helloyj


random include and images


Published in: PHP 


  1. <?
  2.  
  3. $path="random/";
  4.  
  5. if ($dir = @opendir("$path")) {
  6. while (($file = readdir($dir)) !== false) {
  7. if(is_file("$path$file")){
  8. $filearray[]="$file";
  9. }
  10. }
  11. closedir($dir);
  12. }
  13.  
  14. $filename=$filearray[rand(0,count($filearray)-1)];
  15. $ext=explode(".",$filename);
  16. $ext=$ext[1];
  17. if($ext=="gif" or $ext=="jpg"){
  18. print("<img src=\"$path$filename\">");
  19. }
  20. else{
  21. include("$path$filename");
  22. }
  23.  
  24. ?>

Report this snippet 

You need to login to post a comment.