如何通过PHP获取系统驱动器? [英] how to get system drives through php?

查看:163
本文介绍了如何通过PHP获取系统驱动器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:





<我正在建立一个简单的文件浏览器,我想知道如何获得系统信息,如总驱动器和通过PHP脚本名称?


谢谢 解决方案

对于Windows(因为您没有指定操作系统)使用 COM 类。



注意:这与客户端无关。

 <?php 
$ fso = new COM('Scripting.FileSystemObject');
$ D = $ fso->驱动器;
$ 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)。 免于:。 FILE_SIZE($ DO->总计TOTALSIZE);
} else {
$ n =[Drive not ready];
}
回显驱动器。 $ dO-> DriveLetter。 : - 。 $ type [$ dO-> DriveType]。 - 。 $ n。 - 。 $ s。 <峰; br> 中;


$ b函数file_size($ size)
{
$ filesizename = array(Bytes,KB,MB, GB,TB,PB,EB,ZB,YB);
返回$ size? ($ size / pow(1024,($ i = floor(log($ size,1024)))),2)。 $ filesizename [$ i]:'0 Bytes';
}


?>

会输出类似于

<$ p $驱动器C: - 固定 - Bla - 88.38 GB免费:444.14 GB
驱动器D: - 固定 - Blas - 3.11 GB免费:21.33 GB
驱动器E: - 固定 - HP_TOOLS - 90.1 MB免费:99.02 MB
驱动器F: - 光盘 - [驱动器未准备就绪] -
驱动器G: - 光盘 - USB - 0字节免费:24.75 MB
Drive H: - Removable - [Drive not ready] -


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

解决方案

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] - 

这篇关于如何通过PHP获取系统驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆