The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. October 14, 2019, 07:29:15 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: How to measure file size before download.  (Read 4315 times)
tommytx
Expert
****
Offline Offline

Posts: 123


View Profile WWW
« on: July 23, 2011, 07:04:34 PM »

I have found a ton of files that will measure file size when you are on the specific server, but what I need to do is measure the file size before downloading from remote... For example the server php curl program finds a file but if its like greater than 5ok do not down load.... is this possible without downloading the file just for measure...

I could i suppose strart the download.. normally using file_get_contents() or something similar if there was a way to monitor the download and shutdown the file_get_contents() once the download exceeded 50k... is anything like that possible...  Thanks for any suggestions....

It would be nice to measure before the download begins... but if monitored you could stop to save the download of say a 200 meg file.. UGH!


Thoughts suggestions... most of these will be blog pages..

Logged
Bompa
Administrator
Lifer
*****
Offline Offline

Posts: 564


Where does this show?


View Profile
« Reply #1 on: July 23, 2011, 07:36:31 PM »

With perl I use HEAD instead of GET in order to get the file size

You could check this out

http://icfun.blogspot.com/2008/07/php-get-server-response-header-by.html

Bompa
Logged

"The most beautiful and profound emotion we can experience is the sensation of the mystical..." - Albert Einstein
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: July 24, 2011, 12:39:37 AM »

Exactly Bomps, and it's essentially the same in PHP.

You'd have to use cURL or a hand rolled request rather than simply file_get_contents, but it can be done. I think my web class here in the PHP library could be used to do it rather easily.

So Tommy you'd scrape the page for all graphic refs, then HEAD for each to get the sizes.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: July 24, 2011, 12:42:08 AM »

Yep, here you go: http://www.perkiset.org/forum/php/perks_new_webrequest_class-t616.0.html;msg4201#msg4201

Code is at that post. The very first line of the packet is GET, that's where you'd switch to a HEAD and modify the rest of the request body a bit.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
kurdt
Lifer
*****
Offline Offline

Posts: 1153


paha arkkitehti


View Profile
« Reply #4 on: July 24, 2011, 03:58:20 AM »

I have heard from reliable source that by looking at the file's nose size, you can approximate the size.
Logged

I met god and he had nothing to say to me.
tommytx
Expert
****
Offline Offline

Posts: 123


View Profile WWW
« Reply #5 on: July 24, 2011, 12:47:40 PM »

Thanks for all the great suggestions... I am sure I can get one to work..
In regard to measuring the size of graphics.. I may not need that as I am only concerned about the size of the html.

Basically I am assuming that if the page html exceeds 100k it is rarely a normal blog page... however I realize that if it had a ton of posts it might be huge... but for my use if 100k I dont' want it anyway..

so I am assuming its much easier when you only need to measure html page size..... am I right...

Anyway i will study all the ideas you have given and figure out the best way to go...

Unless anyone has any last minute thoughts on the best way to measure html size... without download...
Cause if its 200meg it takes forever to download.. and I want to avoid a download if the page exceeds 100k

Is there a way to measure the page's nose or were you just pulling my leg... hee...heee.


Thanks..
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #6 on: July 24, 2011, 01:04:47 PM »

The HEAD method will work on any HTML pull Tommy, so it will do what you are looking for.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
tommytx
Expert
****
Offline Offline

Posts: 123


View Profile WWW
« Reply #7 on: July 25, 2011, 07:30:53 AM »

Thanks...
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!