2

Possible Duplicate:
How to get system info in PHP?

I am building a simple file browser, I want to know as how to get the system information like the total drives and there names through php script?

thanks

Community
  • 1
  • 1
Maverick
  • 2,738
  • 24
  • 91
  • 157
  • 3
    Since PHP is executed ON the server, I think you cant access your local (client) file system with it (and so system drives etc.). Thats the reason why file browsers etc. are written in Javascript on websites.... – philomatic Nov 21 '11 at 09:58
  • 2
    @PaddyG OP didnt specify whether he wants to build a file browser for the server or the client – Gordon Nov 21 '11 at 10:00
  • With @PaddyG, if you'd retrieve the disks etc through php you would make a browser for your server. – TJHeuvel Nov 21 '11 at 10:01
  • 1
    You're right Gordon, i just assumed that. +1 – philomatic Nov 21 '11 at 10:03
  • Take a look at http://www.gerd-tentler.de/tools/filemanager/ besides its main feature (ftp) it has an option for local file systems, When I first started work with php, I ended up reverse engineering this program. – HTDutchy Nov 21 '11 at 10:09

1 Answers1

13

This is gotten from the manual, and is for windows (Since you didn't specify the OS.) using the COM class.

Note : This has nothing to do with the client side.

<?php
 $fso = new COM('Scripting.FileSystemObject'); 
    $D = $fso->Drives; 
    $type = array("Unknown","Removable","Fixed","Network","CD-ROM","RAM Disk"); 
    foreach($D as $d ){ 
       $dO = $fso->GetDrive($d); 
       $s = ""; 
       if($dO->DriveType == 3){ 
           $n = $dO->Sharename; 
       }else if($dO->IsReady){ 
           $n = $dO->VolumeName; 
           $s = file_size($dO->FreeSpace) . " free of: " . file_size($dO->TotalSize); 
       }else{ 
           $n = "[Drive not ready]"; 
       } 
   echo "Drive " . $dO->DriveLetter . ": - " . $type[$dO->DriveType] . " - " . $n . " - " . $s . "<br>"; 

    } 

      function file_size($size) 
      { 
      $filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"); 
      return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0 Bytes'; 
      } 


?> 

Would output something similar to

Drive C: - Fixed - Bla - 88.38 GB free of: 444.14 GB
Drive D: - Fixed - Blas - 3.11 GB free of: 21.33 GB
Drive E: - Fixed - HP_TOOLS - 90.1 MB free of: 99.02 MB
Drive F: - CD-ROM - [Drive not ready] - 
Drive G: - CD-ROM - Usb - 0 Bytes free of: 24.75 MB
Drive H: - Removable - [Drive not ready] - 
Mob
  • 10,958
  • 6
  • 41
  • 58