PHP: ldir

(PHP 4, PHP 5) ldir – List files and directories inside the specified path.

Description

Mixed ldir(string $directory[, array $hiddentypes[, array $hiddenfiles[, $GET]]])

Parameters

$directory

The directory to be displayed (Absolute or Relative)

$hiddentypes

The filetypes (extensions) to hide i.e. .php Include “.?” to hide dot files/folders.

$hiddenfiles

Individual files to hide. (The script hides itself (or anything with the same name [to fix]))

$GET

Deprecated in 1.8.0
Any additional GET variables to be passed. This allows ldir to be used with more complicated scripts. [Added in Version 1.7.0 onwards] [Deprecated in Version 1.8.0 onwards]

Return Values

Returns echo’d HTML.
Returns bool true int 2 if there was a minor problem (folder/file permissions)
Returns bool true int 3 if there was a minor problem (cannot retrieve icons) Removed in 1.7.9
Returns bool true int 4 if it detects an injection attack (only for admin/logging use)
Returns false if there is any other problem i.e. Directory doesn’t exist.
Use === rather than == to determine which error code is produced.
NOTE: File sizes over 2GB maybe incorrect, see PHP Filesize

Example

ob_start();
$types = array(".php",".exe",".?");
$files = array("index.php","README.txt");
.... code ....
ldir("/location/to/folder",$types,$files);
Output:
[Folder] /location/to/files
Type	FileName	Size
[icon]	filename/link	filesize

Licensing

Versions 1.6.6 onwards

Versions Prior to 1.6.6

  • No License but deemed as Gratis (like free Beer but not Free Speech) i.e. don’t edit the code!

Changelog

View / Download Raw Changelog

Version 1.8.1

  • Improved the automatic $_GET parameter code.
  • Added a HTML comment to display the microtime it took to generate the output.

Version 1.8.0

  • Deprecating the $GET parameter as it can be found via the $_SERVER superglobal
  • Modified the method that ldir detects it’s own script name

Version 1.7.11

  • Shamelessly Added a Link Back (use CSS to hide .ldir_link)

Version 1.7.10

  • Speed optimisations
  • Rewrote icon checking
  • Added supported common icons list
  • Suppressed header() / ob_flush() calls
  • Fixed ‘parent folder’ link not working

Version 1.7.9

  • Speed Optimisations
  • Removed/Condensed more code (9% smaller compared to previous version)
  • Removed icon host check

Version 1.7.8

  • Added better support for styling – Removed inline width CSS & Added CSS styles for each column
  • Removed some linebreaks.
  • Removed/Condensed some code (upto 7% smaller)
  • Custom UserAgent in CURL Opts.

Version 1.7.7

  • Changed the Update URL.

Version 1.7.6

  • Rewrote the PHP4 scandir support so its mildly faster
  • Edited the file/folder checkingn system so its less resource hungry
  • Added Support for different icon hosts
  • Migrated icons to dropbox.

Version 1.7.5

  • Removed more legacy CSS that may have been an issue for users with custom CSS
  • Capitialised the first character of the visible directory name / download location
  • Changed the folder refresh method so it didn’t force a cache reload

Version 1.7.4

  • Changed strripos and stripos to strpos & stripos to make it PHP4 compatible (again)(See 1.7.3-1)
  • Added a class to update text and refresh div so they can be hidden.
  • Removed some legacy CSS forcing elements to be blue

Info and Downloads

Requirements:

OS: Any
Dependencies: PHP 4/5, PHP-cURL
Optional: None
Network: Any
License: GNU GPL v3