How do you filesize of an image from DB?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do you filesize of an image from DB?

Post by Celauran »

Something isn't adding up here.

Code: Select all

echo round(35681 / 1024); // 35
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How do you filesize of an image from DB?

Post by Christopher »

What did you expect? The result is 34.8447265625 which would round to 35. Did you want floor()?
(#10850)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do you filesize of an image from DB?

Post by Celauran »

simonmlewis wrote:It's actually 35,681 bytes.
simonmlewis wrote:The script states 32KB
Floor, ceil, round, there's no way it should give 32. Something else is afoot here.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do you filesize of an image from DB?

Post by simonmlewis »

On Windows Explorer: 34.8KB
Using the PHP Script: 32KB. Not rounded: 32894

It's not totally important to be accurate, but odd that isnt' anyway.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How do you filesize of an image from DB?

Post by Celauran »

OK, so it is accurate. Good.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: How do you filesize of an image from DB?

Post by Eric! »

Here's an example from linux:
[text]-rw------- 1 user user 289059 Sep 19 18:04 photo.jpg[/text]
Bytes are 289059.

But using the build in kB format it's not so correct:
[text]-rw------- 1 user user 283K Sep 19 18:04 photo.jpg[/text]

From php:
[text]filesize=289059
filesize/1024=282.2841796875[/text]

PHP is the exact answer.
priyankagound
Forum Commoner
Posts: 27
Joined: Thu Sep 19, 2013 2:53 am

Re: How do you filesize of an image from DB?

Post by priyankagound »

Try out this one.
You will get the complete reference in the below link.

http://www.phpeasystep.com/phptu/3.html

Hope this helps you.
Post Reply