Example 56-1. General usage
<?php
require_once 'System/WinDrives.php';
//if you want to read the names, pass "true" as first parameter
//this may crash your php.exe, so it's disabled by default
$wd = new System_WinDrives(false);
echo 'API available: ';
echo $wd->isApiAvailable() ? 'yes' : 'no';
echo "\r\n";
$arInfo = $wd->getDrivesInformation();
foreach ($arInfo as $strDrive => $objInfo) {
echo $strDrive . "\r\n";
echo ' Type: ' . $objInfo->type . "\r\n";
echo ' Type title: ' . $objInfo->typetitle . "\r\n";
echo ' Name: ' . $objInfo->name . "\r\n";
?> |
At first, you need to instantitiate a new
System_WinDrives object. You can pass
"true" as parameter to enable hard disk names, but that can
crash PHP and is disabled by default.
The next thing to do is checking if the class can be used.
That depends on the available extensions (win32api on PHP4,
and php_ffi on PHP5). If the isApiAvailable
method returns true, everything is ok.
Now that everything is ok, you can read the driver information
via getDrivesInformation and display the output.
In case the API is not available, the method tries to guess the
drive list by checking if the root directories exist.