Page 1 of 1

List the drives on my computer using PHP

Posted: Fri Jul 30, 2010 4:13 am
by rupeshkumar_rj
I am developing an application where I need to show the drives which exists on my computer (Windows). I need some assistance on implementing this functionality.

I was able to get the drive in which my code file is placed.

Ex:
If my code file is placed in this path :- E:/Apps/thisapp/codefile.php, then I was able to access the E: drive and list its contents by using the function - opendir().

Code: Select all

opendir('/');

But I need to go one more level up and list all the drives in my Windows PC.

Re: List the drives on my computer using PHP

Posted: Fri Jul 30, 2010 5:05 pm
by ndee

Re: List the drives on my computer using PHP

Posted: Fri Jul 30, 2010 8:20 pm
by Weirdan
ndee wrote:This should help.

http://php.net/manual/en/book.w32api.php
Not really. This is dead extension.

You can get drive letters using COM though:

Code: Select all

$fso = new COM('Scripting.FileSystemObject');
foreach ($fso->Drives as $drive) {
	var_dump($drive->DriveLetter);
}

Re: List the drives on my computer using PHP

Posted: Mon Aug 02, 2010 4:22 am
by rupeshkumar_rj
Thanks Weirdan,
I have successfully used the COM method to access the drives. Can we also use this method on UNIX machines also?

Re: List the drives on my computer using PHP

Posted: Mon Aug 02, 2010 4:38 am
by Weirdan
rupeshkumar_rj wrote: Can we also use this method on UNIX machines also?
No.

Re: List the drives on my computer using PHP

Posted: Mon Aug 02, 2010 4:56 am
by requinix
rupeshkumar_rj wrote:Can we also use this method on UNIX machines also?
Hurr. Unix doesn't even have drive letters...

Re: List the drives on my computer using PHP

Posted: Mon Aug 02, 2010 5:05 am
by rupeshkumar_rj
yeah :D .. Unix doesn't have drive letters. How can I implement the same in Unix.

Like, access the root directory using my PHP application.

and If I need to use the same application for both Win and Unix, how can I identify the OS using php and then proceed further.

Re: List the drives on my computer using PHP

Posted: Mon Aug 02, 2010 5:21 am
by requinix
rupeshkumar_rj wrote:Like, access the root directory using my PHP application.
Root is just /.
rupeshkumar_rj wrote:and If I need to use the same application for both Win and Unix, how can I identify the OS using php and then proceed further.
Look at the PHP_OS constant.