List the drives on my computer using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rupeshkumar_rj
Forum Newbie
Posts: 5
Joined: Fri Jul 30, 2010 4:00 am

List the drives on my computer using PHP

Post 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.
ndee
Forum Newbie
Posts: 2
Joined: Tue Jun 15, 2010 5:54 am

Re: List the drives on my computer using PHP

Post by ndee »

User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: List the drives on my computer using PHP

Post 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);
}
rupeshkumar_rj
Forum Newbie
Posts: 5
Joined: Fri Jul 30, 2010 4:00 am

Re: List the drives on my computer using PHP

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: List the drives on my computer using PHP

Post by Weirdan »

rupeshkumar_rj wrote: Can we also use this method on UNIX machines also?
No.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: List the drives on my computer using PHP

Post by requinix »

rupeshkumar_rj wrote:Can we also use this method on UNIX machines also?
Hurr. Unix doesn't even have drive letters...
rupeshkumar_rj
Forum Newbie
Posts: 5
Joined: Fri Jul 30, 2010 4:00 am

Re: List the drives on my computer using PHP

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: List the drives on my computer using PHP

Post 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.
Post Reply