Share Pastebin
Guest
Public paste!

vovanbo

By: a guest | Jun 17th, 2009 | Syntax: PHP | Size: 1.10 KB | Hits: 210 | Expires: Never
Copy text to clipboard
  1. <?php
  2. require_once('../config.php');
  3.  
  4. $output = '';                   // Here we buffer the JavaScript code we want to send to the browser.
  5. $delimiter = "\n";              // for eye candy... code gets new lines
  6.  
  7. $output .= 'var tinyMCEImageList = new Array(';
  8.  
  9. $directory = $image_list_dir;
  10.  
  11. if (is_dir($directory)) {
  12.     $direc = opendir($directory);
  13.  
  14.     while ($file = readdir($direc)) {
  15.         if (!preg_match('~^\.~', $file)) {              // no hidden files / directories here...
  16.             if (is_file("$directory/$file")) {
  17.                 $output .= $delimiter
  18.                     . '["'
  19.                     . $file
  20.                     . '", "'
  21.                     . URL_PUBLIC."$image_public_path/$file"
  22.                     . '"],';
  23.             }
  24.         }
  25.     }
  26.  
  27.     $output = substr($output, 0, -1);           // remove last comma from array item list (breaks some browsers)
  28.     $output .= $delimiter;
  29.  
  30.     closedir($direc);
  31. }
  32.  
  33. $output .= ');';                // Finish code: end of array definition. Now we have the JavaScript code ready!
  34.  
  35. echo $output;                   // Now we can send data to the browser because all headers have been set!
  36.  
  37. ?>