[SOLVED] Disk space...

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
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

[SOLVED] Disk space...

Post by Joe »

Is it possible to tell how much disk space I have used using PHP. If so, how?.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Do you mean disk space on the machine that is running PHP?
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Yeah, like how much space all of my website files are using. disk_total_space() is a big no no, however using this little snippet I made is useful:

Code: Select all

echo nl2br(str_replace(" ", "  ", shell_exec("du -chx ".$_SERVERї'DOCUMENT_ROOT'])));
All I need to do now is parse out the dir name, and calculate the overall size. Arrays and regular expressions should hopefully work :D

Any other suggestions?.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

No worries guys. I found that using 'c' as the only argument gives the total size :D

Cheers!.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

glad we could be of assistance :wink:
Post Reply