Example

Example – How to use System_WinDrives

Using System_WinDrives

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.

Enumerating drives on Windows systems (Previous) Constants defined and used in System_WinDrives (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.