Page 1 of 1
Folder Size
Posted: Sat Nov 27, 2004 1:16 pm
by genetix
Title: Folder Size
Enviroment: File Management System
Programming Languages: PHP, HTML
My problem is that I have a File Management system thats working okay but when it comes to detecting the size of a folder where a clients information is I'm haveing a problem.
Each client has a folder(there username) under a main hosting folder.
../hosting/$username/
I have a script that detects the number of Bytes I think it is in a folder but what I want is to change that into megabytes. Also. Will this script count the number of bytes in other folders in the main $username folder?
Code: Select all
<?php
$select = mysql_fetch_array(mysql_query("SELECT * FROM clients WHERE username='$username' LIMIT 1"));
$dir = "C:/AppServ/www/hosting/$username/";
$megabyte = '1048576';
$ds = disk_total_space($dir);
$su = round($ds/$megabyte);
?>
Heres a link to a demo account for the File Management System. Login as demo with the username demo.
http://www.webdummy.net/serverpro/login.php
Under the space: heading the first set of numbers is $ds and the one under that is $megabyte
Where it says: 108771 / 100 that should be megabytes / 100
Posted: Sat Nov 27, 2004 9:13 pm
by genetix
I'm on a kinda tight deadline. I'm pretty sure I just have a problem with my symbol for devision.
Can anyone help?
Posted: Sat Nov 27, 2004 10:46 pm
by John Cartwright
untested
Code: Select all
<?php
$sql = "SELECT `username` FROM clients WHERE username='$username' LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$dir = "C:/AppServ/www/hosting/$row['username']/";
$megabyte = '1048576';
if ($handle = opendir($dir) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$totalsize += filesize($file);
}
}
closedir($handle);
$totalmb = round($ds/$megabyte);
echo 'total is '.$totalmb.'mb';
?>
Posted: Mon Nov 29, 2004 5:32 pm
by genetix
Sorry that doesn't work out well. I will post my whole script so its easyer to see.
As this is only 1/4 of the page a $username variable is declared much earlier. That is available.
Code: Select all
<?php
if(!$security) {
echo "This page is ONLY to be used WITH the main page of the Server Pro File Manager!";
die;
}
mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$select = mysql_fetch_array(mysql_query("SELECT * FROM clients WHERE username='$username' LIMIT 1"));
$dir = "C:/AppServ/www/hosting/$username/";
$megabyte = '1048576';
$ds = disk_total_space($dir);
$su = round($ds/$megabyte);
$sa = $select[space];
$pv = $select[pageviews];
$apv = $select[allowedpv];
$sd = $select[subdomains];
$asd = $select[allowedsd];
echo "
<tr>
<td bgcolor='#0099CC'><div align='left'>Space(magabytes)$ds<br>$megabyte</div></td>
<td bgcolor='#0099CC'>$su / $sa</td>
</tr>
<tr>
<td bgcolor='#0099CC'><div align='left'>Page Views</div></td>
<td bgcolor='#0099CC'>$pv / $apv</td>
</tr>
<tr>
<td bgcolor='#0099CC'><div align='left'>Sub-domains</div></td>
<td bgcolor='#0099CC'>$sd / $asd</td>
</tr>
<tr>
<td bgcolor='#00CCFF' height=100%></td>
<td bgcolor='#00CCFF' height=100%></td>
</tr>
<tr>
<td colspan='2'></td>
</tr>";
?>
Posted: Mon Nov 29, 2004 5:49 pm
by genetix
I just tried something else but now its trying to get the files in the folder the script is in...
Code: Select all
<?php
if(!$security) {
echo "This page is ONLY to be used WITH the main page of the Server Pro File Manager!";
die;
}
mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$select = mysql_fetch_array(mysql_query("SELECT * FROM clients WHERE username='$username' LIMIT 1"));
$dir = 'C:/AppServ/www/hosting/'.$username.'/';
$megabyte = '1048576';
if ($handle = opendir($dir)) {
while (false != ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$totalsize += filesize($file);
}
}
closedir($handle);
}
$ds = round($ds/$megabyte);
/*
$handle = opendir($dir);
if($handle = opendir($dir)) {
$ds = disk_total_space($handle);
$su = round($ds/$megabyte);
}
$dir = "C:/AppServ/www/hosting/$username/";
$megabyte = 1048576;
$ds = disk_total_space($dir);
$su = round($ds/$megabyte);
*/
$sa = $select[space];
$pv = $select[pageviews];
$apv = $select[allowedpv];
$sd = $select[subdomains];
$asd = $select[allowedsd];
echo "
<tr>
<td bgcolor='#0099CC'><div align='left'>Space(magabytes)$ds<br>$megabyte<br>$dir</div></td>
<td bgcolor='#0099CC'>$su / $sa</td>
</tr>
<tr>
<td bgcolor='#0099CC'><div align='left'>Page Views</div></td>
<td bgcolor='#0099CC'>$pv / $apv</td>
</tr>
<tr>
<td bgcolor='#0099CC'><div align='left'>Sub-domains</div></td>
<td bgcolor='#0099CC'>$sd / $asd</td>
</tr>
<tr>
<td bgcolor='#00CCFF' height=100%></td>
<td bgcolor='#00CCFF' height=100%></td>
</tr>
<tr>
<td colspan='2'></td>
</tr>";
?>
Warning: filesize(): Stat failed for aaw6181.exe (errno=2 - No such file or directory) in c:\appserv\www\webdummy\www\serverpro\sp_left.php on line 15
Warning: filesize(): Stat failed for working.ph (errno=2 - No such file or directory) in c:\appserv\www\webdummy\www\serverpro\sp_left.php on line 15
Posted: Wed Dec 01, 2004 4:15 pm
by genetix
I narrowed it down some more. I figured out that the file is not "attainable." I added an or die statement to the function that checks the file size. Its now reporting the error of "file not attainable" like scripted.
What permissions must I have the file set to to allow people to detect the size of the folder?