ngg_ajax_file_browser

JQuery File Tree PHP Connector.

Description

(string) ngg_ajax_file_browser(); 

Returns (string)

folder content


Usage

  1. if ( !function_exists( 'ngg_ajax_file_browser' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextcellent-gallery/admin/ajax.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = ngg_ajax_file_browser(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/admin/ajax.php  
  1. function ngg_ajax_file_browser() { 
  2.  
  3. global $ngg; 
  4.  
  5. // check for correct NextGEN capability 
  6. if ( !current_user_can('NextGEN Upload images') && !current_user_can('NextGEN Manage gallery') ) 
  7. die('No access'); 
  8.  
  9. if ( !defined('ABSPATH') ) 
  10. die('No access'); 
  11.  
  12. // if nonce is not correct it returns -1 
  13. check_ajax_referer( 'ngg-ajax', 'nonce' ); 
  14.  
  15. // start from the default path 
  16. $root = trailingslashit ( WINABSPATH ); 
  17. // get the current directory 
  18. $dir = trailingslashit ( urldecode($_POST['dir']) ); 
  19.  
  20. if( file_exists($root . $dir) ) { 
  21. $files = scandir($root . $dir); 
  22. natcasesort($files); 
  23.  
  24. // The 2 counts for . and .. 
  25. if( count($files) > 2 ) { 
  26. echo "<ul class=\"jqueryDirTree\" style=\"display: none;\">"; 
  27.  
  28. // return only directories 
  29. foreach( $files as $file ) { 
  30.  
  31. //reserved name for the thumnbnails, don't use it as folder name 
  32. if ( $file == 'thumbs') 
  33. continue; 
  34.  
  35. if ( file_exists($root . $dir . $file) && $file != '.' && $file != '..' && is_dir($root . $dir . $file) ) { 
  36. echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . esc_html($dir . $file) . "/\">" . esc_html($file) . "</a></li>"; 
  37.  
  38. echo "</ul>"; 
  39.  
  40. die();