Example #1
0
<?php

/**
 * Example file to demonstrate use of directory_info class
 *
 * File: example/example.php
 * @package directory_info
 */
include 'directoryinfo.inc.php';
// Directory path relative to the location of this file
$pathtodir = 'example/tst/';
$dirobj = new directory_info();
$array_ext = array('jpg', 'png', 'zip');
$myList = $dirobj->get_ext_based_filelist(null, $pathtodir, true, $array_ext);
print_r($myList);
echo '<br />';
$myList = $dirobj->get_filelist(null, $pathtodir, false);
print_r($myList);
echo ' - bez podfolderow<br />';
print 'filecount is (bez): ' . $dirobj->filecount;
echo '<br />';
$myList = $dirobj->get_filelist(null, $pathtodir, true);
print_r($myList);
echo ' - z folderami- use recursive<br />';
print 'filecount is (z podfolderem): ' . $dirobj->filecount;
echo '<br />';
$myList = $dirobj->get_human_readable_dirsize(null, $pathtodir, true);
print_r($myList);
echo '<br />';
$myList = $dirobj->get_human_readable_filesize($pathtodir . 'Malta 1266.jpg');
print_r($myList);
 function get_human_readable_file_permissions($pathtofile)
 {
     if (!directory_info::valid_pathtofile($pathtofile)) {
         return false;
     }
     $perms = fileperms($pathtofile);
     if (($perms & 0xc000) == 0xc000) {
         $info = 's';
     } elseif (($perms & 0xa000) == 0xa000) {
         $info = 'l';
     } elseif (($perms & 0x8000) == 0x8000) {
         $info = '-';
     } elseif (($perms & 0x6000) == 0x6000) {
         $info = 'b';
     } elseif (($perms & 0x4000) == 0x4000) {
         $info = 'd';
     } elseif (($perms & 0x2000) == 0x2000) {
         $info = 'c';
     } elseif (($perms & 0x1000) == 0x1000) {
         $info = 'p';
     } else {
         $info = 'u';
     }
     // Unknown
     // Owner
     $info .= $perms & 0x100 ? 'r' : '-';
     $info .= $perms & 0x80 ? 'w' : '-';
     $info .= $perms & 0x40 ? $perms & 0x800 ? 's' : 'x' : ($perms & 0x800 ? 'S' : '-');
     // Group
     $info .= $perms & 0x20 ? 'r' : '-';
     $info .= $perms & 0x10 ? 'w' : '-';
     $info .= $perms & 0x8 ? $perms & 0x400 ? 's' : 'x' : ($perms & 0x400 ? 'S' : '-');
     // World
     $info .= $perms & 0x4 ? 'r' : '-';
     $info .= $perms & 0x2 ? 'w' : '-';
     $info .= $perms & 0x1 ? $perms & 0x200 ? 't' : 'x' : ($perms & 0x200 ? 'T' : '-');
     return $info;
 }
Example #3
0
</pre>

	<p>
		If files/directories within the criteria given were found, the class will return an array with all the information. This allows you to format the results any way you like (i.e. in a select list or displayed on a page or.... )
	</p>
	<p>
		For lots more information on the available methods and variables in this class, have a look at the extensive <a href="../documentation/index.html" title="Go to the documentation">documentation</a> which was provided with this class.
	</p>


	<h2>Instantiating the class</h2>
	<p>To start: let's instantiate the class so it will remember results</p>
	<code>$dirobj = new directory_info();</code>

<?php 
$dirobj = new directory_info();
?>


	<h2>Example 1</h2>
	<p>A list of all image files with jpeg, jpg, gif or png extention in your directory with no information on files in subdirectories</p>
	<code>$myList = $dirobj->get_ext_based_filelist( null, $pathtodir, true );</code>
	<h4>Results in:</h4>

<?php 
$myList = $dirobj->get_ext_based_filelist(null, $pathtodir, true);
print '<pre>filecount is : ' . $dirobj->fileselection_count . '<br /><br />';
print_r($myList);
//	print_r( $dirobj->filelist_selection ); // does the same
print '</pre>';
print '<p>which is a selection against the (larger) total filelist:</p>';