Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 02-04-2009, 06:22 PM   #1
Pics Traffic
Confirmed User
 
Pics Traffic's Avatar
 
Industry Role:
Join Date: Jun 2004
Location: Europe
Posts: 3,055
Php question for gurus: Displaying file size in MB not in bytes

How do you do it?

echo filesize("0001.wmv");

is doing to show bytes. How do you format it to show in MB's ?
Pics Traffic is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-04-2009, 06:25 PM   #2
Voodoo
♥ ♦ ♣ ♠
 
Voodoo's Avatar
 
Industry Role:
Join Date: Sep 2002
Posts: 10,592
mb=bytes\1024\1024
__________________

"I'm selflessly supporting the common good, but only coincidentally looking out for No.1."

Last edited by Voodoo; 02-04-2009 at 06:26 PM..
Voodoo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-04-2009, 06:27 PM   #3
Juicy D. Links
So Fucking Banned
 
Industry Role:
Join Date: Apr 2001
Location: N.Y. -Long Island --
Posts: 122,992
Code:
  
function formatbytes($file, $type)   
{   
    switch($type){   
        case "KB":   
            $filesize = filesize($file) * .0009765625; // bytes to KB   
        break;   
        case "MB":   
            $filesize = (filesize($file) * .0009765625) * .0009765625; // bytes to MB   
        break;   
        case "GB":   
            $filesize = ((filesize($file) * .0009765625) * .0009765625) * .0009765625; // bytes to GB   
        break;   
    }   
    if($filesize <= 0){   
        return $filesize = 'unknown file size';}   
    else{return round($filesize, 2).' '.$type;}   
}

Code:
// USAGE   
echo formatbytes("$_SERVER[DOCUMENT_ROOT]/images/large_picture.jpg", "MB");   
// would display the file size in MB

Last edited by Juicy D. Links; 02-04-2009 at 06:28 PM..
Juicy D. Links is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-04-2009, 06:33 PM   #4
Pics Traffic
Confirmed User
 
Pics Traffic's Avatar
 
Industry Role:
Join Date: Jun 2004
Location: Europe
Posts: 3,055
Quote:
Originally Posted by Juicy D. Links View Post
Code:
  
function formatbytes($file, $type)   
{   
    switch($type){   
        case "KB":   
            $filesize = filesize($file) * .0009765625; // bytes to KB   
        break;   
        case "MB":   
            $filesize = (filesize($file) * .0009765625) * .0009765625; // bytes to MB   
        break;   
        case "GB":   
            $filesize = ((filesize($file) * .0009765625) * .0009765625) * .0009765625; // bytes to GB   
        break;   
    }   
    if($filesize <= 0){   
        return $filesize = 'unknown file size';}   
    else{return round($filesize, 2).' '.$type;}   
}

Code:
// USAGE   
echo formatbytes("$_SERVER[DOCUMENT_ROOT]/images/large_picture.jpg", "MB");   
// would display the file size in MB

you're the man Juicy. Now do the eyebrow for me again like you did in Atlanta at the bar. I need to show you that pix Thanks Bro.
Pics Traffic is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-04-2009, 06:39 PM   #5
Juicy D. Links
So Fucking Banned
 
Industry Role:
Join Date: Apr 2001
Location: N.Y. -Long Island --
Posts: 122,992
Quote:
Originally Posted by MOCKBA View Post
you're the man Juicy. Now do the eyebrow for me again like you did in Atlanta at the bar. I need to show you that pix Thanks Bro.


hehehe
Juicy D. Links is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-04-2009, 06:53 PM   #6
Bro Media - BANNED FOR LIFE
MOBILE PORN: IMOBILEPORN
 
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
Quote:
Originally Posted by Juicy D. Links View Post
Code:
  
function formatbytes($file, $type)   
{   
    switch($type){   
        case "KB":   
            $filesize = filesize($file) * .0009765625; // bytes to KB   
        break;   
        case "MB":   
            $filesize = (filesize($file) * .0009765625) * .0009765625; // bytes to MB   
        break;   
        case "GB":   
            $filesize = ((filesize($file) * .0009765625) * .0009765625) * .0009765625; // bytes to GB   
        break;   
    }   
    if($filesize <= 0){   
        return $filesize = 'unknown file size';}   
    else{return round($filesize, 2).' '.$type;}   
}

Code:
// USAGE   
echo formatbytes("$_SERVER[DOCUMENT_ROOT]/images/large_picture.jpg", "MB");   
// would display the file size in MB
Juicy knows PHP? LIES!!

Good job, I was about to post something similar for him.
Bro Media - BANNED FOR LIFE is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-04-2009, 07:17 PM   #7
Ozarkz
So Fucking Banned
 
Join Date: Jan 2009
Posts: 2,377
Quote:
Originally Posted by Retox Josh View Post
Juicy knows PHP? LIES!!

Good job, I was about to post something similar for him.

No you weren't.
Ozarkz is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-04-2009, 07:23 PM   #8
Juicy D. Links
So Fucking Banned
 
Industry Role:
Join Date: Apr 2001
Location: N.Y. -Long Island --
Posts: 122,992
the code is from google btw
Juicy D. Links is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-04-2009, 09:10 PM   #9
Bro Media - BANNED FOR LIFE
MOBILE PORN: IMOBILEPORN
 
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
Quote:
Originally Posted by Ozarkz View Post
No you weren't.
Fuck off fake nick.
Bro Media - BANNED FOR LIFE is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2009, 01:46 AM   #10
Azathoth
Confirmed User
 
Join Date: Nov 2002
Location: Blah
Posts: 217
Quote:
Originally Posted by Juicy D. Links View Post
Code:
  
function formatbytes($file, $type)   
{   
    switch($type){   
        case "KB":   
            $filesize = filesize($file) * .0009765625; // bytes to KB   
        break;   
        case "MB":   
            $filesize = (filesize($file) * .0009765625) * .0009765625; // bytes to MB   
        break;   
        case "GB":   
            $filesize = ((filesize($file) * .0009765625) * .0009765625) * .0009765625; // bytes to GB   
        break;   
    }   
    if($filesize <= 0){   
        return $filesize = 'unknown file size';}   
    else{return round($filesize, 2).' '.$type;}   
}

Code:
// USAGE   
echo formatbytes("$_SERVER[DOCUMENT_ROOT]/images/large_picture.jpg", "MB");   
// would display the file size in MB
On the reutrn you could also do
return(number_format($filesize, 2, '.', ',').' '.$type)

This would show something like 1,321.26 KB etc.

- Az
Azathoth is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2009, 04:35 AM   #11
ExLust
Confirmed User
 
ExLust's Avatar
 
Join Date: Aug 2008
Posts: 3,223
Quote:
Originally Posted by Juicy D. Links View Post
Code:
  
function formatbytes($file, $type)   
{   
    switch($type){   
        case "KB":   
            $filesize = filesize($file) * .0009765625; // bytes to KB   
        break;   
        case "MB":   
            $filesize = (filesize($file) * .0009765625) * .0009765625; // bytes to MB   
        break;   
        case "GB":   
            $filesize = ((filesize($file) * .0009765625) * .0009765625) * .0009765625; // bytes to GB   
        break;   
    }   
    if($filesize <= 0){   
        return $filesize = 'unknown file size';}   
    else{return round($filesize, 2).' '.$type;}   
}

Code:
// USAGE   
echo formatbytes("$_SERVER[DOCUMENT_ROOT]/images/large_picture.jpg", "MB");   
// would display the file size in MB
Thanks. I save this.
__________________

BE A PARTNER
ExLust is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2009, 04:41 AM   #12
edgeprod
Permanently Gone
 
Industry Role:
Join Date: Mar 2004
Posts: 10,019
Quote:
Originally Posted by Retox Josh View Post
Juicy knows PHP? LIES!!

Good job, I was about to post something similar for him.
It would have been hilarious if you saw what he posted before the edit. I did a double-take and was like "wait, that's a built-in function now?!" hehe.

But props for finding it and posting it, Juicy.
edgeprod is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2009, 05:23 AM   #13
Juicy D. Links
So Fucking Banned
 
Industry Role:
Join Date: Apr 2001
Location: N.Y. -Long Island --
Posts: 122,992
Quote:
Originally Posted by edgeprod View Post
It would have been hilarious if you saw what he posted before the edit. I did a double-take and was like "wait, that's a built-in function now?!" hehe.

But props for finding it and posting it, Juicy.
only have basic code exp from years ago just basics n shit lolll yeah i had to look at the code before i realized it was missing something loll
Juicy D. Links is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2009, 07:12 AM   #14
Bro Media - BANNED FOR LIFE
MOBILE PORN: IMOBILEPORN
 
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
Quote:
Originally Posted by edgeprod View Post
It would have been hilarious if you saw what he posted before the edit. I did a double-take and was like "wait, that's a built-in function now?!" hehe.

But props for finding it and posting it, Juicy.
Quote:
Originally Posted by Juicy D. Links View Post
only have basic code exp from years ago just basics n shit lolll yeah i had to look at the code before i realized it was missing something loll
Lmfao, I take it he just posted the usage bit? Nice one Juicy!
Bro Media - BANNED FOR LIFE is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-05-2009, 08:06 AM   #15
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
Juicy has giant code balls
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.