4

Using php i have contents of a file through file_get_contents() function. I want to calculate the size of the file using the contents. Is there a precise way to do it ?

I tried strlen(contents) , suggested in one of the answers , but there is quite difference in size returned and actual file size on computer.

Note : using ubuntu 12.04

EDIT : sorry for the waste of time guys, it seems the contents were base64_encode() which led to mismatch in sizes. I appreciate your time and effort. Sorry again.

8

2 Answers 2

1

Check filesize() for that and try like this

$filename = 'somefile.txt'; echo $filename . ': ' . filesize($filename) . ' bytes';
Sign up to request clarification or add additional context in comments.

1 Comment

I dont have the file location , only contents :(
5

if strlen() doesn't return the length in bytes, check that 'function overloading' of mbstring is not enabled : http://www.php.net/manual/en/mbstring.overload.php

1 Comment

function overloading of mbstring is not enabled and strlen() does return the size in bytes

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.