GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Php question for gurus: Displaying file size in MB not in bytes (https://gfy.com/showthread.php?t=885910)

Pics Traffic 02-04-2009 06:22 PM

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 ?

Voodoo 02-04-2009 06:25 PM

mb=bytes\1024\1024

Juicy D. Links 02-04-2009 06:27 PM

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


Pics Traffic 02-04-2009 06:33 PM

Quote:

Originally Posted by Juicy D. Links (Post 15440086)
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.

Juicy D. Links 02-04-2009 06:39 PM

Quote:

Originally Posted by MOCKBA (Post 15440115)
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 :pimp

Bro Media - BANNED FOR LIFE 02-04-2009 06:53 PM

Quote:

Originally Posted by Juicy D. Links (Post 15440086)
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.

Ozarkz 02-04-2009 07:17 PM

Quote:

Originally Posted by Retox Josh (Post 15440161)
Juicy knows PHP? LIES!!

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


No you weren't.

Juicy D. Links 02-04-2009 07:23 PM

the code is from google btw

Bro Media - BANNED FOR LIFE 02-04-2009 09:10 PM

Quote:

Originally Posted by Ozarkz (Post 15440229)
No you weren't.

Fuck off fake nick.

Azathoth 02-05-2009 01:46 AM

Quote:

Originally Posted by Juicy D. Links (Post 15440086)
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

ExLust 02-05-2009 04:35 AM

Quote:

Originally Posted by Juicy D. Links (Post 15440086)
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.

edgeprod 02-05-2009 04:41 AM

Quote:

Originally Posted by Retox Josh (Post 15440161)
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. :1orglaugh 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.

Juicy D. Links 02-05-2009 05:23 AM

Quote:

Originally Posted by edgeprod (Post 15441411)
It would have been hilarious if you saw what he posted before the edit. :1orglaugh 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

Bro Media - BANNED FOR LIFE 02-05-2009 07:12 AM

Quote:

Originally Posted by edgeprod (Post 15441411)
It would have been hilarious if you saw what he posted before the edit. :1orglaugh 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 (Post 15441536)
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!

nation-x 02-05-2009 08:06 AM

Juicy has giant code balls


All times are GMT -7. The time now is 06:49 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123