473,796 Members | 2,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1324
>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
5714
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 code: Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
0
1318
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 FileInfo(ImageFilePath.PostedFile.FileName).Length is also quit easy. However, obtaining the Height and Width in Pixels is difficult. I need this information to automatically resize the Image (creating Thumbnails and other formats for a Storefront application). ...
4
1321
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 strictly ASP method. Any help will be appreciated, Thanks -- / Sean the Mc /
3
11097
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 the code, to check whether all the Connections are closed. everything is perfect, and infact the connections are closed in the finally block.
4
23193
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 may have occurred because all pooled connections were in use and max pool size was reached. Below is my code. Any help will be appreciated.
15
2241
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
2776
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 gives is: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
4
5644
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 if anyone could help. All I am trying to do is obtain a string representation of a Version Info value for a given file. Currently, I am only getting strange unicode characters, so not sure if my problem is in the understanding of the functions...
2
12619
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 in use and max pool size was reached. Target Site:- MySql.Data.MySqlClient.Driver GetConnection() Error Source:- MySql.Data
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9533
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10239
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10190
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.