如何使用PHP来检测计算机上的所有驱动器?这一发现将包括:
如何在多个平台(如Linux和Windows )上完成这一任务?
发布于 2016-02-18 03:00:13
如果您使用的是Linux,您可以使用PHP的exec()函数执行以下两个命令:
fdisk -l其中列出磁盘和分区如下:
Disk /dev/xvda1: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/xvda1 doesn't contain a valid partition table
Disk /dev/xvda2: 365.0 GB, 365041287168 bytes
255 heads, 63 sectors/track, 44380 cylinders, total 712971264 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/xvda2 doesn't contain a valid partition table
Disk /dev/xvda3: 939 MB, 939524096 bytes
255 heads, 63 sectors/track, 114 cylinders, total 1835008 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/xvda3 doesn't contain a valid partition table这个命令是:
mount其中列出了活动挂载点,包括交换点。产出如下:
/dev/xvda1 on / type ext4 (rw)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
fusectl on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
/dev/xvda2 on /mnt type ext3 (rw)通过解析这些驱动器的输出,您可以获得所有驱动器的信息。在Linux中有更多的命令(例如cat /proc/partitions)可用,您可以探索其他的方法。
对于Windows来说,它更复杂。您可以使用(所需的管理特权):
fsutil fsinfo drives返回(内容不多):
Drives: C:\ D:\ E:\ F:\详细的驾驶信息可通过以下途径获得:
diskpart然后发行:
list volume然后将显示以下输出:
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 E DVD-ROM 0 B No Media
Volume 1 System Rese NTFS Partition 100 MB Healthy System
Volume 2 C System NTFS Partition 99 GB Healthy Boot
Volume 3 F Data (local NTFS Partition 365 GB Healthy但是,由于PHP无法执行命令并对输入多个命令,所以您可能无法直接获取信息。考虑使用批处理程序输出所需的信息,并使用PHP调用该批处理程序。
https://stackoverflow.com/questions/35471796
复制相似问题