Showing Drive Information Using PHP – Info PHP

Introduction

This article shows how to see all the information. In this article we use a COM object. COM is an abbreviate of Component Object Model; this object is an object oriented layer on top of DCE RPC (open standard) and defines a common calling rules that is followed by any language. The code can be loaded from a DLL.
 
There is a subset of COM known as OLE Automation that is a set of COM interfaces that allow loose binding to COM Objects, so that we called them run-time without compile-time knowledge of how the object works. The PHP COM extension utilizes the OLE Automation interface to allow us to create and call something.
 
COM is the only way to communicate with a Windows platform. Using COM we can launch a Microsoft Word document, like open a Word document, do any task in Word and send it to a visitor’s web site.

Syntax:

$obj= new COM(“Application.ID”)

If you will encounter any Fatel error : Class ‘COM’ not found
[COM_DOT_NET]extension=php_com_dotnet.dll
Add this code into your php.ini file

Syntax

$obj= new COM(“Application.ID”)

If you encounter a Fatel error : Class ‘COM’ not found

Then use the following procedure to remove this fatal error.

Step 1

Open the php.ini file. It might be in the file location “C:Program FilesIIS ExpressPHPv5.4”.

Step 2

PHPINIFile

And paste the following code as shown in the picture .

[COM_DOT_NET]extension=php_com_dotnet.dll

?php
$fileObj = new COM(‘Scripting.FileSystemObject’);
$DriveObj = $fileObj->Drives;
$type = array(“Unknown”,“Removable”,“Fixed”,“Network”,“CD-ROM”,“RAM Disk”);
foreach($DriveObj as $d )
{
     $dO = $fileObj->GetDrive($d);
     $s = “”;
     if($dO->DriveType == 3)
     {
         $n = $dO->Sharename;
      }

     else
if($dO->IsReady)
     {
     $n = $dO->VolumeName;
     $s = sizeOfFile($dO->FreeSpace) . ” free of: “ . sizeOfFile($dO->TotalSize);
     }
    
else{
     $n = “[Drive not ready]”;
     }
     echo “Drive “ . $dO->DriveLetter . “: – “ . $type[$dO->DriveType] . ” – “ . $n . ” – “ . $s .
;
}
function sizeOfFile($size)
{
    $filesizename = array(” Bytes”, ” KB”, ” MB”, ” GB”);
    return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : ‘0 Bytes’;
}
?>

Output

ListAllDrive
Summary

In this article we saw how to get all the information about the computer’s drives.

Article Prepared by Ollala Corp

You might also like More from author

Leave A Reply

Your email address will not be published.