Windows you can use COM, it’s much more faster than trying to script something. Unix/Linux popen works great!
Windows…. PHP via (COM)
$f = 'f:/www/docs';
$obj = new COM ( 'scripting.filesystemobject' );
if ( is_object ( $obj ) )
{
$ref = $obj->getfolder ( $f );
echo ‘Directory: ‘ . $f . ‘ => Size: ‘ . $ref->size;
$obj = null;
}
else
{
echo ‘can not create object’;
}
?>
Linux one way…
$f = './path/directory';
$io = popen ( '/usr/bin/du -sk ' . $f, 'r' );
$size = fgets ( $io, 4096);
$size = substr ( $size, 0, strpos ( $size, ' ' ) );
pclose ( $io );
echo 'Directory: ' . $f . ' => Size: ‘ . $size;
?>
Benchmark for windows:
File: 36,133 Folders: 6,210
Time taken to return total size: 19.614099 seconds
Script output: Directory: K:/Windows => Size: 7506880321
Computer Configs:
CPU: Intel 3 GHz
RAM: 512MB
Hard-disk: 80GB SATA 7,200RPM Seagate
This is great for installers. It checks the file you provided in thefirst statment, against the octal you want it to have. If it hasincorrect permissions, the row is red, if correct permissions, it makesa green row.
Function
PHP Code:
function check_perms($path,$perm)
{
clearstatcache();
$configmod = substr(sprintf(’%o’, fileperms($path)), -4);
$trcss = (($configmod != $perm) ? "background-color:#fd7a7a;" : "background-color:#91f587;");
echo "<tr style=".$trcss.">";
echo "<td style="border:0px;">". $path ."</td>";
echo "<td style="border:0px;">$perm</td>";
echo "<td style="border:0px;">$configmod</td>";
echo "</tr>";
}
Usage
PHP Code:
<table width="100%" border="0" cellspacing="0" cellpadding="3" style="text-align:center;">
<tr>
<th style="border:0px;"><b>File Name</b></th>
<th style="border:0px;"><b>Needed Chmod</b></th>
<th style="border:0px;"><b>Current Chmod</b></th>
</tr>
<?php
check_perms("cache","0777");
check_perms("include/keys","0777");
check_perms("backup","0777");
check_perms("uploads","0777");
check_perms("include/template","0777");
check_perms("include/user","0777");
check_perms("img","0777");
check_perms("img/avatars","0777");
?>
</table>
This function will read the full structure of a directory. It’s recursive becuase it doesn’t stop with the one directory, it just keeps going through all of the directories in the folder you specify.
PHP Code:
<?php
function getDirectory( $path = ‘.’, $level = 0 ){
$ignore = array( ‘cgi-bin’, ‘.’, ‘..’ );
// Directories to ignore when listing output. Many hosts
// will deny PHP access to the cgi-bin.
$dh = @opendir( $path );
// Open the directory to the handle $dh
while( false !== ( $file = readdir( $dh ) ) ){
// Loop through the directory
if( !in_array( $file, $ignore ) ){
// Check that this file is not to be ignored
$spaces = str_repeat( ‘ ’, ( $level * 4 ) );
// Just to add spacing to the list, to better
// show the directory tree.
if( is_dir( "$path/$file" ) ){
// Its a directory, so we need to keep reading down…
echo "<strong>$spaces $file</strong><br />";
getDirectory( "$path/$file", ($level+1) );
// Re-call this same function but on a new directory.
// this is what makes function recursive.
} else {
echo "$spaces $file<br />";
// Just print out the filename
}
}
}
closedir( $dh );
// Close the directory handle
}
?>
Example Calls:
PHP Code:
getDirectory( "." );
// Get the current directory
getDirectory( "./files/includes" );
// Get contents of the "files/includes" folder
- Set up an error document in your .htaccess file that redirects every single 404 to a file called maybe redirection.php
- Add a wildcard DNS record in your zone files, so that [whateverhere].yourdomain.com points to the domain IP.
- Add a wildcard serveralias in your apache configs by using:
ServerAlias *.yourdomain.com - Write the following code in your redirection.php file
$url=$_SERVER["REQUEST_URL"];
$newurl=str_replace(".yourdomain.com","",$url);
$newcomplete="http://yourdomain.com/".$newurl;
Header("Location: ".$newcomplete);
?>
So when someone enters a subdomain, let’s say myself.yourdomain.com they get redirected to yourdomain.com/myself.
The benefits of online learning are open to every one. There are hundreds of sites offering online training as well as study guides regarding latest courses like 640-863 as well as 350-018. The helping materials about Microsoft exams such as 70-554 are also accessible online. These online courses and exams not only benefit students from all over the world but also help the working people. As employees of any web hosting firms providing reliable services of domain hosting and domain parking can improve their services through passing these exams and can offer more steadfast backup along advanced hosting plans.
















