473,382 Members | 1,365 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,382 software developers and data experts.

Displaying webpage size?

Ajm113
161 100+
Quick question; How can I get the file size of the web page?
Aug 7 '07 #1
13 4386
pbmods
5,821 Expert 4TB
Heya, AJM.

Navigate to the directory and execute an `ls -l` or Get Info in the Finder :P

Alternatively, you might be interested in the filesize() function.
Aug 7 '07 #2
Ajm113
161 100+
Sometimes when I want to try stuff like this in php. They have a simple function out of it! X|

Thanks!
Aug 7 '07 #3
Ajm113
161 100+
Actually it is not working! I thought it would work on the first try, but no. Its not displaying anything! I want it to be able to read the file size of websites.

[PHP]$GetSite = $_GET['url'];

$f = fopen($filesize, 'r');

==HTML==

<tr>
<td>File Size:</td>
<td><? echo filesize($filesize) .' bytes'; ?><hr></td>
</tr>[/PHP]
Aug 7 '07 #4
pbmods
5,821 Expert 4TB
Heya, AJM.

Is $filesize the full path to the file? Try using file_exists(), or file_get_contents() to make sure that the file you're looking for is really there.
Aug 7 '07 #5
Ajm113
161 100+
Well I do have those working now, but they seem not to help me a lot.
Aug 8 '07 #6
kovik
1,044 Expert 1GB
Well I do have those working now, but they seem not to help me a lot.
Working how? That the file exists? If so, then filesize doesn't work remotely.

You may want to look into using cURL and it's settings for dealing with headers.
Aug 8 '07 #7
Ajm113
161 100+
Here is how:
[PHP]if(file_exists($GetSite))
{
echo filesize($GetSite) .' bytes';
}else{
echo"<font color=\"#FF0000\">Error: Can't get file size!</font>";
}[/PHP]

I don't know where to look for what you suggested.
Aug 8 '07 #8
pbmods
5,821 Expert 4TB
Heya, AJM.

What would be an example of the value of $GetSite?
Aug 9 '07 #9
Ajm113
161 100+
Three examples:

1. http://www.domain3233.com

2.http://www.domain3233.com/Folder/

3.http://www.domain3233.com/Folder/page.ext

I am trying to get this going so I can have the user be able to see what the page size is on my site.

Just click on the "?" mark after the green url under a result.
Aug 9 '07 #10
pbmods
5,821 Expert 4TB
Heya, AJM.

filesize() only works on local files. Are these files hosted on the same server as your filesize script? Try using the file path instead of the URL.

If these files are hosted on a different server, here's my recommendation:
  • Contact the individual who runs the other site and ask him to set up a filesize script or else provide you with the filesizes, or...
  • Set up a cron script to download the files every night and cache their sizes. Then, instead of calculating the size of each file, you'd use the stored values (how often would the filesize change, anyway).
  • If there's a LOT of files, you might want to store the last (e.g.,) 3 sizes that your script found, and for each file where all three values are the same, only download it, say, once per week instead.
Aug 9 '07 #11
kovik
1,044 Expert 1GB
Again, cURL will do what you're after. curl_getinfo() will prove useful.
Aug 10 '07 #12
pbmods
5,821 Expert 4TB
Again, cURL will do what you're after. curl_getinfo() will prove useful.
I think from a design standpoint, what this script really needs is a way to cache filesizes. Suppose there are 10 files that you need to determine the sizes of, and each one averages 1 MB. That means that EVERY time the User loads a page, he has to wait for your server to download 10 MB.

AND, what happens when one User loads the page, and while he's waiting, a second User attempts to load the page? The second User will likely have to wait not only for the server to download all the files for him, but he'll have to also wait for the server to finish downloading the last User's files!

On the other hand, if the server were to automatically cache these filesizes by downloading the files once per week, then it can fetch these saved values instantaneously, plus it saves bandwidth... and how often are these files going to significantly change in size, anyway?
Aug 10 '07 #13
kovik
1,044 Expert 1GB
I agree with you, but not from a 'design standpoint,' but more in the way of saving bandwidth, both for the server and the client. It's always a good idea to save results and only update when necessary, but I also think it's a good idea to use cURL in order to accomplish this particular example, along with saving the results. cURL has a lot of options, and I believe you can specify exactly how much of the remote document you would like to retrieve. You can get only the request header, which should have the file size in it, and if not, I'm sure theres a way to do it without having to retrieve the entire file. Files usually give their file size within themselves.
Aug 12 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Jason Steeves | last post by:
Can someone please point me in the right direction for displaying word documents onto a webpage? The word documents will contain text/tables/pictures. I am new to this and can't quite find what I...
10
by: Johan Christensson | last post by:
Hi. Is there any other ways of displaying a webpage in an VB.Net form other then using the "Microsoft Web Browser" object? Any third-party? /Johan Ch
13
by: comp.lang.php | last post by:
I have currently devised a way to display up to 3,000 records via PHP/HTML by using pagination techniques that stuff an entire DB query resultset into a $_SESSION object to use within pagination. ...
12
by: M.L. | last post by:
When loaded from my hard drive, the webpage I'm working on renders fine on IE6, Firefox 2.0.0.1, and Opera 9.02. However, after uploading it to the web there are 2 images that fail to display on...
1
by: sureshreddy | last post by:
hi friends, I want the time to be displayed for a webpage to redirect to another webpage. You can see this concept in job sites when we fill all the details and click the search button it displays...
3
by: hestres | last post by:
Hello, I'm working on some link styles for this page: http://www.house.gov/velazquez/lh0205tres/reports.html I want all the links to always display in red (#CC0000), but in IE6 and 7 they...
4
by: Blue10 | last post by:
Hi, I would like to be able to display thumbnail versions of the full images on my website. Currently I have to make the thumbnails manually so I wonder if there is any way of displaying reduced...
3
by: mikec87 | last post by:
I am very new with PHP...started doing this a few days ago to help someone and I need some help please. I have a webpage that is not displaying the records I want it to. The sql is correct, and I...
6
by: Jeff | last post by:
hi asp.net 2.0 I have a image (.jpeg) stored in sql server 2005 and now I want to display it on a webpage. So I created a webpage (Image.aspx) which just writes the buffer data to the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...

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.