View Full Version : Detecting a page size without saving
Single Paradox
11-17-2005, 02:31 AM
I am making a javascript page that pretty much acts like frontpage, you can type code into a box and preview the code. With this code I am going to have a dialog box that tells you how big the page is (in bytes or KB), and I need a php script that works similar to the filesize() function. The only reason I can't use the filesize() function is because the page being displayed isn't saved, so there is no URL to put into filesize(). Does anyone understand what I am looking for? I am sorry I am being a little foggy.
Thanks in advance, Tom
missing-score
11-17-2005, 02:38 AM
say the form variable name was "content", you could get it by using:
<?php
$filesize = strlen( $_POST['content'] );
?>
But if this is a JavaScript based page, could you not just use:
var filesize = document.getElementById( 'content' ).value.length;
Single Paradox
11-17-2005, 02:41 AM
Oh yes, I know how to check the charactor length in javascript. BUT I'm asking for the ACTUAL PAGE filesize in bytes or KB. With all the elements and stuff functional, not just the letters of the code.
Velox Letum
11-17-2005, 03:12 AM
It is irrelevant as the browser downloads the entire source then draws the various elements. The only problem you might have is images, which you might get beforehand and simply add on to the total.
Fissure
11-17-2005, 05:55 AM
Oh yes, I know how to check the charactor length in javascript. BUT I'm asking for the ACTUAL PAGE filesize in bytes or KB. With all the elements and stuff functional, not just the letters of the code.
Essentially, the page filesize is the number of characters in it's markup(aka the length of the string) times the amount of bits a character takes. (ussually 1 byte, depends on if its written in Unicode(2 bytes) or ASCII(1 byte).) If you wish to calculate image sizes you might want to search the code for <img> tags and then get that files size, although that seems dumb.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.