Filesizer plugin, a couple (unofficial) mods
Posted: 27 June 2007 03:25 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1735
Joined  03-26-2006

Back on this thread, ExpressionEngineer wrote a plugin called Filesizer, which happened to be something I was looking for today.

Lealea had a request on that thread to make the filesizer output jump from kb to MB automatically. I made that mod as well as others such as outputting the file extension if desired (which is shown in the pic), and easier integration with Mark Huot’s File module.

I thought it might be useful to outline what I did for the kb/MB issue, in case anyone wants to make a quick (unofficial) mod to their copy of the plugin. See the attached pic for the kb/MB output, which is automatic.

Find this:

if ( @file_exists($file) )
        
{
            $fs
= @filesize($file);
            
            
// one could easily add more units here later on..
            
if ( $units == "mb" ) $div = 1024 * 1024;
            if (
$units == "kb" ) $div = 1024;
            
            if (
$decimals == 0)
            
{
                $fs
= ceil($fs / $div);
            
}
            
elseif ($decimals > 0)
            
{
                $fs
= round(($fs / $div), $decimals);
            
}
        }

        
return $this->return_data = $fs;
    
} // end filesizer


Change to:

if ( @file_exists($file) )
        
{
            $fs
= @filesize($file);
            
$units = array("b", "kb", "MB", "GB");
            
$units_count = count($units);
            
            for(
$unit = 0; $unit < $units_count && $fs >= 1024; $unit++)
                        
{
                        $fs
/= 1024;
                        
}
            
// Don't include decimals if size is b or kb
                
$decimals = $unit < 2 ? 0 : $decimals;
                 
$sizedata = number_format($fs, $decimals) . " " . $units[$unit];
        
}
            
return $this->return_data = $sizedata;
        
}
    }
// end filesizer


Then you can comment out the line about units (line 27) and just output a tag like this, with no units declared:

{exp:filesizer filename="{your_file}" upload_pref="3"}

Image Attachments
dlock_sample.png
Click thumbnail to see full-size image
 Signature 

ryan masuga
—————
Masuga Design | Member, EE Pro Network
My EE Add-Ons | {devot:ee}
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
Posted: 27 June 2007 09:52 PM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1593
Joined  01-05-2007

I get a big blank Plugin page if I implement these changes…

The original plugin works fine though.

 Signature 

 
Steven Hambleton | ExpressionEngine Development for Web & Graphic Design Agencies

Profile
 
 
Posted: 28 June 2007 12:24 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  569
Joined  07-22-2004

Ryan, thanks for the mod!
I hope you don’t mind I updated the plugin with your code, ever so slightly modified.

 Signature 

ExpressionEngineer - custom solutions for EE

I EE

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65026 Total Logged-in Users: 42
Total Topics: 82116 Total Anonymous Users: 17
Total Replies: 441305 Total Guests: 199
Total Posts: 523421    
Members ( View Memberlist )
Newest Members:  meenoiYang.JianuoioitsukiNathan HammondalexcigadamstaneckiLucas Mayscybermilltstitt