473,395 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

obtaining the size of a file

I need to obtain the filesize of a file thats not on the same server. As
filesize() need a realpath and not a url how else can this be done?
Feb 26 '06 #1
3 1306
>I need to obtain the filesize of a file thats not on the same server. As
filesize() need a realpath and not a url how else can this be done?


Fetch the file and look at the size of it?

How *can* you access this file? Some FTP servers will provide the
file size if you ask them nicely. HTTP doesn't (unless you get the
file too). And if it's dynamic content, it might be a different
size every time you fetch it.

Gordon L. Burditt

Feb 26 '06 #2
I need to obtain the filesize of a file thats not on the same server. As
filesize() need a realpath and not a url how else can this be done?


Fetch the file and look at the size of it?

How *can* you access this file? Some FTP servers will provide the
file size if you ask them nicely. HTTP doesn't (unless you get the
file too). And if it's dynamic content, it might be a different
size every time you fetch it.


Hmm, could you make a HEAD request? That has a content size header,
although I don't know if you'd have to factor in the size of the header
itself and whether any encoding is used.

---
Steve

Feb 26 '06 #3
Steve wrote:
Hmm, could you make a HEAD request? That has a content size header,
although I don't know if you'd have to factor in the size of the
header itself and whether any encoding is used.


Sure, per ezample:

$host = 'www.google.com';
$path = '/images/logo.gif';
$bytes = 0;

if ($fp = fsockopen($host, 80)) {
fputs($fp, "HEAD $path HTTP/1.0\r\n");
fputs($fp, "Host: $host\r\n\r\n");
while (!feof($fp) && !$bytes) {
if (preg_match('/content\-length\s*:\s*(\d+)/i',
fgets($fp, 1024),
$m)) {
$bytes = $m[1];
}
}
fclose($fp);
}

print "size is $bytes bytes";
JW
Feb 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin | last post by:
Dear Group Sorry for posting this here. I'm desperate for a solution to this problem and thought some of you might have come across it with .NET and SQL Server. Let's assume I've the following...
0
by: Lennart Hoglund | last post by:
Uploading an Image to a Server using the method described in the Knowledge Base article Q315832, works fine and smoothly. Obtaining the Image Size using; ImageSize.Text = New...
4
by: What-a-Tool | last post by:
Is there an ASP method for obtaining the size of the clients display area? Think I can think of a method(havn't tried it yet) combining JavaScripting and ASP, but I was wondering if there was a...
3
by: Kamalanathan T. | last post by:
Hi, We have developed an Web application in ASP.NET with C# and we r using SQL Server 2000. We get the Timeout expired error, when more than 300 concurrent users hit the site. I hagone thru...
4
by: Guoqi Zheng | last post by:
Dear sir, I keep getting the following errors on one of my sites after clicking for many times. Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This...
15
by: kris | last post by:
Hi I am writing a small program where I need to obtain the actual size of a structure. The programm is as follows struct abc { int j; char k; int i; }*a;
7
by: =?Utf-8?B?Sm9obiBTdGFnZ3M=?= | last post by:
Hello, Please read this all before giving an answer :) I'm doing some troubleshooting on a web application that my company wrote. It's written in asp.net 1.1. The error that the Event viewer...
4
by: =?Utf-8?B?anBzaG9ydHN0dWZm?= | last post by:
Hi, not sure if this is the right place for this but it was definitely the closest I could find. I am having trouble with the GetFileVersionInformation/VerQueryValue functions and was wondering...
2
by: anumsajeel | last post by:
Hi, Error Message:- error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.