hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : PHP : howto find remote file header ?
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

PHP : howto find remote file header ?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 01-09-2006, 01:46 PM
goolex goolex is offline
Web Hosting Master
 
Join Date: Jul 2004
Posts: 868

PHP : howto find remote file header ?


Hi

i wana know how can i know remote file size without downloading that file
is this possible ? how ?

thanks

Reply With Quote


Sponsored Links
  #2  
Old 01-09-2006, 02:03 PM
thomas7 thomas7 is offline
Web Hosting Master
 
Join Date: Jul 2004
Location: Kent, UK
Posts: 699
HTTP Headers normally tell you the size of the file.
Grab the HTTP headers.
You can use some sort of socket to just get the headers on the file.

__________________
Andrew Thomas

Reply With Quote
  #3  
Old 01-09-2006, 02:10 PM
goolex goolex is offline
Web Hosting Master
 
Join Date: Jul 2004
Posts: 868
Quote:
Originally Posted by thomas7
HTTP Headers normally tell you the size of the file.
Grab the HTTP headers.
You can use some sort of socket to just get the headers on the file.
yes but i dont know how can i use php to grab file header

Reply With Quote
Sponsored Links
  #4  
Old 01-09-2006, 02:15 PM
thomas7 thomas7 is offline
Web Hosting Master
 
Join Date: Jul 2004
Location: Kent, UK
Posts: 699
Sorry, didn't realise you already knew that.
I don't write PHP, i'm a perl person.
There is a dedicated module in perl, so theres probabally one for php.
Here's a simple method.

$server = fsockopen($host, $port);
fputs($server, $frombrowser);
$topheaders=fgets($server, 1024);

This will return the first 1K of data. That should contain a header.
I think $frombrowser should be the file you are requesting maybe?? GET /file.html HTTP/1.1

This is just out of some code that i've got lying around. Not my code mind

__________________
Andrew Thomas

Reply With Quote
  #5  
Old 01-09-2006, 02:23 PM
thomas7 thomas7 is offline
Web Hosting Master
 
Join Date: Jul 2004
Location: Kent, UK
Posts: 699
Found out that for the $frombrowser you also need to give it a
Host: www.test.com
Then just split $topheaders down into the part you need.
Content-Length: X is what your after.

__________________
Andrew Thomas

Reply With Quote
  #6  
Old 01-09-2006, 02:47 PM
Korvan Korvan is offline
Web Hosting Guru
 
Join Date: Nov 2005
Posts: 268
what thomas7 has stated will work in php.

Check this page for another good example of an http request using fsockopen
http://us2.php.net/manual/en/function.fsockopen.php

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Gladinet Launches Cloud Enterprise Service to Access SAN as a Private Cloud Web Hosting News 2013-03-28 14:19:44
Hosting.com's New Online Backup Solution Offers Remote and Local Options Web Hosting News 2012-03-13 16:34:57
Pancake.io, DropPages Let Users Host Web Site Files on DropBox Blog 2011-12-08 17:03:11
Web Host Rackspace Adds New Features to Cloud Load Balancer Web Hosting News 2011-09-16 16:35:04
Patch Released for Apache Software DDoS Vulnerability Web Hosting News 2011-08-26 15:03:10


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?