TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-20-2007, 02:03 PM   #1 (permalink)
The Visitor
 
alex.zeal's Avatar
 
Join Date: Sep 2007
Posts: 2
Thanks: 0
alex.zeal is on a distinguished road
Method to check Size of Remote File

Hello dear friends, I wanna know the method to check the size of targeted url... In other words if I wanna download a file "example.rar" from url "http://example.com/prg/rip/example.rar" I wanna chk the size of "example.rar" with help PHP code. And also wanna apply same code on all extensions like .zip, .rar, .mpg, .jpg, .htm, .tar or any other. Is it possible with any method...:)
alex.zeal is offline  
Reply With Quote
Old 09-20-2007, 02:17 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Sometimes the remote server will return you the Content-Length in the HTTP header. However, failing that, the way I would do it is:

PHP Code:
$szFile file_get_contents('http://www.google.co.uk/intl/en_uk/images/logo.gif');
echo 
round(strlen($szFile) / 10242) . 'KB'
This is assuming that all the characters are 1 byte a piece. 2 byte characters, such as Japanese characters, will give a bad reading, but you should be fine.

Needless to say that the Content-Length in the header is the way forward because the file doesn't need to be downloaded first - this is fine though with smallish files.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 09-21-2007, 11:51 PM   #3 (permalink)
The Visitor
 
alex.zeal's Avatar
 
Join Date: Sep 2007
Posts: 2
Thanks: 0
alex.zeal is on a distinguished road
:)

Dear tht I think u don't got my point I actually wanna the size of file for example 'exaple.rar' file is of size 2mb... I want help in code so that when I enter url for instance imagine 'www.exmpl.com/as/example.rar' in a text box then after clicking submit button it return the size of the 'example.rar' or generate error message if url is not valid...

I think HTTP Header help out in this problem but I don't know how to Print it....


PHP Code:
$szFile file_get_contents('http://www.google.co.uk/intl/en_uk/images/logo.gif');
echo 
round(strlen($szFile) / 10242) . 'KB'
Dear I think this code help to get the size of url string not the targeted gif file. I wanna the size of gif file...
alex.zeal is offline  
Reply With Quote
Old 09-22-2007, 12:29 AM   #4 (permalink)
The Wanderer
 
Join Date: Sep 2007
Posts: 11
Thanks: 0
Chaos King is on a distinguished road
Default

This is what you are talking about, at least this is what I can infer from your posts.

PHP Code:
function getSize $url )
{
    if ( 
intval(phpversion()) < )
        die ( 
'PHP5 Required' );
    
    
$headers get_headers $url);
    return 
$headers['Content-Length'];
}

echo 
getSize 'http://www.google.com/images/firefox/fox1.gif' ); 


You will need PHP5 in order for this function to operate, you can use a php4 replacement, you would have to find the function or write it yourself at http://php.net/get_headers in the comments section.

It gets the headers of the file, which does not download the file itself (this will make it faster than using file_get_contents

Was this what you had in mind?
Chaos King is offline  
Reply With Quote
Old 09-22-2007, 10:22 AM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

That's the function - get_header() !
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:37 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design