hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Calculate disk space used with PHP?
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Calculate disk space used with PHP?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 08-10-2005, 02:44 PM
P-nut P-nut is offline
Retired Moderator
 
Join Date: Jun 2003
Location: Proud She-Geek
Posts: 1,719

Calculate disk space used with PHP?


I'm on a server using cpanel and would like to code something simple to display a user's disk space usage to them. I don't have root access to the server and don't want the users to have direct cpanel access.

Is it possible to achieve this using PHP?

__________________
<?php echo "Signature here"; ?>

Reply With Quote


Sponsored Links
  #2  
Old 08-10-2005, 07:57 PM
Tomer Tomer is offline
WHT Addict
 
Join Date: Oct 2003
Location: Israel
Posts: 132
You want to show how much diskspace a certain directory is using?

- Tomer

__________________
Christmas time is among us, get your loved ones Designer Fragrances

Reply With Quote
  #3  
Old 08-10-2005, 08:33 PM
P-nut P-nut is offline
Retired Moderator
 
Join Date: Jun 2003
Location: Proud She-Geek
Posts: 1,719
That's right.

__________________
<?php echo "Signature here"; ?>

Reply With Quote
Sponsored Links
  #4  
Old 08-10-2005, 08:37 PM
Tomer Tomer is offline
WHT Addict
 
Join Date: Oct 2003
Location: Israel
Posts: 132

__________________
Christmas time is among us, get your loved ones Designer Fragrances

Reply With Quote
  #5  
Old 08-10-2005, 09:48 PM
P-nut P-nut is offline
Retired Moderator
 
Join Date: Jun 2003
Location: Proud She-Geek
Posts: 1,719
Thanks. That sort of helps; however I end up with the free space on the entire disk partition, and not just the user's directory

__________________
<?php echo "Signature here"; ?>

Reply With Quote
  #6  
Old 08-11-2005, 05:50 AM
Roy@ENHOST Roy@ENHOST is offline
Web Hosting Master
 
Join Date: Feb 2002
Location: San Diego CA
Posts: 1,480
The fact that you dont have root access makes it hard.
You would like to use cURL to retrieve a user's Account Info page and use regex to get the free disk space.
The catch is that you need the user's loginname & password.
Ive done something similar and it works. Good luck though.

__________________
What you can do with Cpanel ------------------> |||||
What you can do with Cpanel XP+CpanelAPP -------> ||||||||||||||||||||||||||||||||||||||||

Your competitors are cashing in with Cpanel XP & CpanelAPP, are you?

Reply With Quote
  #7  
Old 08-11-2005, 06:03 AM
arkin arkin is offline
Web Hosting Guru
 
Join Date: Feb 2003
Location: L.A. C.A.
Posts: 334
I think the only way to pick up a users free space is by setting a variable manually to establish how much they start with and then subtract the used space.

I would avoid logging into cPanel via sockets as Roy mentioned, good theory, but could be highly insecure and I would stay away from it.

Reply With Quote
  #8  
Old 08-11-2005, 09:14 PM
P-nut P-nut is offline
Retired Moderator
 
Join Date: Jun 2003
Location: Proud She-Geek
Posts: 1,719
Roy@ENHost kindly pointed me to this script:
http://www.josheli.com/vox/view_sour...disk_usage.php

The only thing is is that it returns all of the users' diskspace that are in my WHM. I only need it to find the user who is logged in and return their disk space usage.

Here's the scrip (I've trimmed some of it to focus on the parts that actually handle the connecting):
PHP Code:
<?php
/*

Report looks like this:

Timestamp: September 14, 2003, 6:55 am

Reseller Total: 84.80
Domain: client1.com -- Space used: 19 Meg
Domain: client2.com -- Space used: 11 Meg
Domain: client3.com -- Space used: 104 Meg
Domain: client4.com -- Space used: 0 Meg
Domain: client5.com -- Space used: 14 Meg
Domain: client6.org -- Space used: 13 Meg
Domain: client7.com -- Space used: 8 Meg
Total space used: 253.8
Remaining space: 246.2


*/

/***********************************************************************
Start of configurable variables
************************************************************************/

$whmUser 'username';
$whmPass 'password';
$cpUser 'username';
$cpPass 'password';
$url 'www.mydomain.com';//do not include 'https://'
$cpTheme 'vertex';
$resellerQuota 500;//in megabytes (e.g. 1.5 gigs would be '1500')

/***********************************************************************
End of configurable variables
************************************************************************/


$msg 'Timestamp: '.date("F j, Y, g:i a")."\n\n";

//get the main reseller account usage from cpanel
//the other possible way to do this is to do a system call to 'du -ms'
$page = @file_get_contents("https://$cpUser:$cpPass@$url:2083/frontend/$cpTheme/main.html");

$int preg_match("/>Disk.*?<\/b>/is",$page$piece);
if(
$int) {
    
//$resellerTotal[1] will contain the value
    
preg_match('/<b>(.*)<\/b>/',$piece[0], $resellerTotal);
    
$msg .= 'Reseller Total: '.$resellerTotal[1]."\n";
}

//now get the WHM 'list accounts' page
$page2 = @file_get_contents("https://$whmUser:$whmPass@$url:2087/scripts2/listaccts?viewall=1");

//get each accounts table row
$int2 preg_match_all("/<tr class=(?:tdshade2|tdshade1)>(.*?)<\/tr>/is"$page2$matches);

if(
$int2 && is_array($matches[1])) {
    foreach(
$matches[1] as $match) {        
        
$account explode('</td><td>',$match);
        
$msg .= 'Domain: '.strip_tags($account[0]).' -- Space used: '.$account[7]."\n";
        
$clientTotal += $account[7];
    }
    
$total ceil($clientTotal $resellerTotal[1]);
    
$msg .= 'Total space used: '.$total." mb \n";

    
$remaining ceil($resellerQuota $total);
    
$msg .= 'Remaining space: '.$remaining." mb \n";
    
    
}
else {
  
$msg .= "No workee.\n";
}

        echo 
nl2br($msg);//to browser
?>
I've been tearing my hair out over this for over 4 hours now. Hoping someone can help!

__________________
<?php echo "Signature here"; ?>

Reply With Quote
  #9  
Old 08-13-2005, 04:35 AM
I'll Host It I'll Host It is offline
Junior Guru Wannabe
 
Join Date: Jul 2005
Location: Seattle, WA
Posts: 37
Code:
<?
system("du -sh /path/to/dir");
?>
If you're lazy, like me. Not the best if the domain is owned by another user or if you really want cpanel integration... will tell you a folder's size though.

__________________
I'll Host It webhosting and file hosting service.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Web Host Certified Hosting Launches New Linux VPS Plans Web Hosting News 2012-08-22 09:08:38
Web Host A2 Hosting Launches Customizable VPS Hosting Plans Web Hosting News 2012-06-07 15:11:57
Web Host Earthnet Launches Xpert.net Linux Web Hosting Services Web Hosting News 2012-03-23 16:09:07
Storm On Demand Boosts Performance with Solid State Drives Cloud Servers Web Hosting News 2012-03-07 14:31:24
Web Hosting Sales and Promos Roundup - September 23, 2011 Web Hosting News 2011-09-23 21:07:12


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?