Source for file WinDrives.php
Documentation is available at WinDrives.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Christian Weiske <cweiske@php.net> |
// +----------------------------------------------------------------------+
// $Id: WinDrives.php,v 1.1 2005/07/10 07:29:39 cweiske Exp $
require_once('PEAR.php');
if (!defined('SYSTEM_WINDRIVE_REMOVABLE')) {
define('SYSTEM_WINDRIVE_ERROR' , 1 );
define('SYSTEM_WINDRIVE_REMOVABLE', 2 );
define('SYSTEM_WINDRIVE_FIXED' , 3 );
define('SYSTEM_WINDRIVE_REMOTE' , 4 );
define('SYSTEM_WINDRIVE_CDROM' , 5 );
define('SYSTEM_WINDRIVE_RAMDISK' , 6 );
* Get drive information on windows systems
* This class gives back a list of existing drives
* (like a:\, c:\ and so) as well as the drive types
* (hard disk, cdrom, network, removable)
* The class requires the php_w32api.dll on php4 and
* the php_ffi.dll for php5
* Note that the php_win32api.dll shipped with normal php
* packages has a problem with many parameters
* This means that the script will crash when trying
* to get the drive name. use "setReadName(false)" to
* On php5, the drive _names_ are always ''.
* You should not use this on non-Windows operating systems
* If you use this class in your projects, I ask you
* to send a real-world postcard to:
* @author Christian Weiske <cweiske@php.net>
* If the drive names shall be enumerated
* This can cause problems with some versions
* of win32api.dll, so it's disabled by default
* The win32api object to use
* If it's null, it can't be used
* The php_ffi object to use
* If it's null, it can't be used
* php_ffi replaces win32api in php5
* List with titles for the drive types
SYSTEM_WINDRIVE_ERROR => 'non-existent',
SYSTEM_WINDRIVE_REMOVABLE => 'Removable',
SYSTEM_WINDRIVE_FIXED => 'Harddisk',
SYSTEM_WINDRIVE_REMOTE => 'Network drive',
SYSTEM_WINDRIVE_CDROM => 'CD-Rom',
SYSTEM_WINDRIVE_RAMDISK => 'RAM-Disk'
* Constructs the class and checks if the api
* @param boolean If the drive names shall be read
$strFuncs = "[lib='kernel32.dll'] long GetLogicalDriveStringsA(long nBufferLength, char *lpBuffer);"
. "[lib='kernel32.dll'] long GetLogicalDrives();"
. "[lib='kernel32.dll'] int GetDriveTypeA(char *lpRootPathName);";
$this->objFFI = new FFI ($strFuncs);
if (class_exists('win32') || PEAR ::loadExtension ('w32api')) {
$this->objApi->registerfunction ("long GetLogicalDriveStrings Alias GetLogicalDriveStrings (long &BufferLength, string &Buffer) From kernel32.dll");
$this->objApi->registerfunction ("long GetLogicalDrives Alias GetLogicalDrives () From kernel32.dll");
$this->objApi->registerfunction ("int GetDriveType Alias GetDriveType (string lpRootPathName) From kernel32.dll");
$this->objApi->registerfunction ("long GetVolumeInformationA Alias GetVolumeInformation (string lpRootPathName, string &lpVolumeNameBuffer, int nVolumeNameSize, int &lpVolumeSerialNumber, int &lpMaximumComponentLength, int &lpFileSystemFlags, string &lpFileSystemNameBuffer, int nFileSystemNameSize) From kernel32.dll");
* returns an array containing information about all drives
* @return array Array with drive infomation
foreach ($arDrives as $strDrive) {
$arInfo[$strDrive]->typetitle = $this->getTypeTitle($arInfo[$strDrive]->type , $strDrive);
* @param boolean If the drive's names shall be read
* return the "bReadName" setting
* checks if the win32 api/ffi is available
* @return boolean True if the api can be used, false if the dll is missing
* returns a list with all drive paths
* like "A:\", "C:\" and so
* @return array Array with all drive paths
//set the length your variable should have
//prepare an empty string
if ($this->objApi->GetLogicalDriveStrings ($len, $buffer)) {
} elseif ($drive_list = $this->objApi->GetLogicalDrives ()) {
$arDrives = $this->splitDriveNumner ($drive_list);
} else if ($this->objFFI !== null ) {
$drive_list = $this->objFFI->GetLogicalDrives ();
if (count($arDrives) == 0 ) {
//nothing found... we'll guess
* splits a number returned by GetLogicalDrives*()
* into an array with drive strings ("A:\", "C:\")
* @param int The number the function gave back
* @return array Array with drives
for ($i=1 , $drv = 65; $drv <= 90; $drv++ ) {
$arDrives[] = chr($drv) . ":\\";
* Tries to guess the drive list
* The floppy "A:\" will no be in the list
* @return array Array with all the drive paths like "A:\" and "C:\"
//DON'T begin with A or B as a message box will pop up
//if no floppy is provided
for ($i = 1 , $drv = 67; $drv <= 90; $drv++ ) {
$arDrives[] = chr($drv) . ':\\';
* @param string Drive path like "C:\"
* @return int Drive type, use "DRIVE_*" constants to enumerate it
$nType = $this->objApi->GetDriveType ($strDrive);
} else if ($this->objFFI !== null ) {
$nType = $this->objFFI->GetDriveTypeA ($strDrive);
* returns the title for a given drive type
* @param int The drive type
* @param string The drive path (like "A:\")
* @return string The type title like "Harddisk"
* returns the name of the drive
* The name is the one the user has given the drive
* like "Windows" or "Data"
* The FFI version doesn't seem to work...
* $strFunc .= "[lib='kernel32.dll'] long GetVolumeInformationA(char lpRootPathName, char *lpVolumeNameBuffer, int nVolumeNameSize, "
. "long *lpVolumeSerialNumber, long *lpMaximumComponentLength, long *lpFileSystemFlags, char *lpFileSystemNameBuffer, int nFileSystemNameSize);";
* @param string Drive path like "C:\"
* @return string The name of the drive
$MaximumComponentLength = 0;
$VolumeNameBuffer = str_repeat("\0", $VolumeNameSize);
$FileSystemNameSize = 260;
$FileSystemNameBuffer = str_repeat("\0", $FileSystemNameSize);
if ($result = $this->objApi->GetVolumeInformation (
$strDrive, $VolumeNameBuffer, $VolumeNameSize,
$serialNo, $MaximumComponentLength,
$FileSystemFlags, $FileSystemNameBuffer, $FileSystemNameSize)) {
$strName = trim($VolumeNameBuffer);
}//class System_WinDrives
Documentation generated on Mon, 11 Mar 2019 14:48:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|