Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-30-2006, 07:25 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default Directory Size

well i want to get the total size of a directory, ive managed to get this code to display the file size of every file in the directory

PHP Code:
<?php

$dir 
"../demo/themes/";
        
$tree = array();
        
$dirs = array(array($dir, &$tree));
       
        for(
$i 0$i count($dirs); ++$i)
        {
                
$d opendir($dirs[$i][0]);
                
$tier =& $dirs[$i][1];

                while(
$file readdir($d))
                {
                        if (
$file != '.' and $file != '..')
                        {
                                
$path $dirs[$i][0] . DIRECTORY_SEPARATOR $file;
                                if (
is_dir($path))
                                {
                                        
$tier[$file] = array();
                                        
$dirs[] = array($path, &$tier[$file]);
                                }
                                else
                                {
                                        
                                    
$size2 filesize($path);
                                    
$size = array($size2);
                                    
print_r($size);
                                    echo 
"<br>";    
                                        
                                }    
                                                                                 
                        }
                        
                }
                
        }
/*

?>
the only problem is adding all them together. my inital idea was to create a array that stores the file size in a new element then just create a loop that adds them all together. the only problem i have is every file size is stored in array element 0

HTML Code:
Array ( [0] => 0 )
Array ( [0] => 881 )
Array ( [0] => 97 )
Array ( [0] => 970 )
Array ( [0] => 1246 )
Array ( [0] => 0 )
Array ( [0] => 123 )
Array ( [0] => 1678 )
Array ( [0] => 1661 )
Array ( [0] => 2184 )
Array ( [0] => 8689 )
All help is appreciated, thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 07-31-2006, 08:23 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,203
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

I've added comments around what I added:

PHP Code:
<?php 

// Add a variable before the loops
$totalSize 0;

$dir "../demo/themes/"
        
$tree = array(); 
        
$dirs = array(array($dir, &$tree)); 
        
        for(
$i 0$i count($dirs); ++$i
        { 
                
$d opendir($dirs[$i][0]); 
                
$tier =& $dirs[$i][1]; 

                while(
$file readdir($d)) 
                { 
                        if (
$file != '.' and $file != '..'
                        { 
                                
$path $dirs[$i][0] . DIRECTORY_SEPARATOR $file
                                if (
is_dir($path)) 
                                { 
                                        
$tier[$file] = array(); 
                                        
$dirs[] = array($path, &$tier[$file]); 
                                } 
                                else 
                                { 
                                         
                                    
$size2 filesize($path); 
                                    
                                    
// Add the Size
                                    
$totalSize += size2;

                                    
$size = array($size2); 
                                    
print_r($size); 
                                    echo 
"<br>";     
                                         
                                }     
                                                                                  
                        } 
                         
                } 
                 
        } 

  
// Show the size
  
print $totalSize;

Also, if you are using an array you should push the value so that it goes in as the last/new element. That would keep them from all being on element 0.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-31-2006, 12:41 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

hm...is this tested?
PHP Code:
print $totalSize
seems to be yielding zero
Code:
Array ( [0] => 799 )
Array ( [0] => 1588 )
Array ( [0] => 1627 )
Array ( [0] => 1515 )
Array ( [0] => 1693 )
0
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-31-2006, 06:45 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,203
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

No, I didn't test it - which I should of before I posted. I will give it a test at work in the morning and post back.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-05-2006, 11:17 PM
smith smith is offline
Programmer
 
Join Date: Jun 2006
Posts: 108
Rep Power: 9
smith is on a distinguished road
Default

Did this ever get resolved?
__________________
Code:
for (int i;;) {
   cout << "Smith";
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 08-06-2006, 02:02 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

Quote:
Originally Posted by smith
Did this ever get resolved?
not yet
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Affiliate Program Directory mysticalone Affiliate Marketplace 2 11-11-2007 12:51 PM
Business Directory SEO TcM Search Engine Optimization 4 08-19-2007 06:50 PM
Othello program!! 24 hours left! siren C and C++ 1 06-14-2007 12:18 PM
Directory Dump: Don't be fooled: It's a great place to market! littlefranciscan Marketing 6 03-04-2007 09:11 AM
root directory Chan PHP Forum 2 08-04-2006 06:59 PM


All times are GMT -5. The time now is 05:21 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads