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

File Size

Ken
Can JavaScript detect the size of an image file?

Ken

Jul 23 '05 #1
2 2717
On Mon, 6 Sep 2004 15:39:18 -0500, Ken wrote:
Can JavaScript detect the size of an image file?


I do not know if there are other ways to do it, but
...does your server return file listings like this?
<http://www.physci.org/test/screenshot/>

That is a directory on my server that contains
no 'index' page, so the server writes a file list
...complete with file size.

Assuming you can access the elements using JS,
you might be able to load that page in a hidden
or IFRAME and parse it for the information.

Be warned though, that I am merely lurking here
trying to pick up tips from the experts. ;-)

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #2
Ken wrote:
Can JavaScript detect the size of an image file?

Ken


No, JavaScript can not. However, at least one user agent has a
host Image object which includes a property that lets you access
the information you require. JavaScript can then be used to
access that host object property:

<url:
http://msdn.microsoft.com/workshop/a...s/filesize.asp
/>

<body onload="alert(document.images['myImage'].fileSize);">
<img name="myImage" src="myImage.gif">
</body>

Note that of IE 6SP1, Firefox 0.9.3, Mozilla 1.7.2, Opera 7.54,
Opera 6.05 and Netscape 4.78, only IE does not report "undefined"
in the above code example.

The other possibility would be to use the XML HTTP Request object
available in IE and Gecko-based browsers to do a HEAD request for
the image. The headers that get returned should contain the image
size (Content-Length) <url:
http://jibbering.com/2002/4/httprequest.html />.

Lastly, if you have any sort of server-side technology available
to you (ASP, JSP, Perl, PHP, etc), you could use it to retrieve
the size of the image and then "pass" that value to the
client-side javascript:

<?php
# use PHP to determine the size of the image
?>
<script type="text/javascript">
var imageSize = <?php echo $imageSize ?>;
</script>

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #3

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

Similar topics

4
by: Joe | last post by:
Hello, I have IIS 6.0 running on w2k3 Enterprise. I have three upload forms 1 to have restricted uploads .asp 2 to upload plain .asp any extension 3 a FP form upload non .asp
17
by: Arnold | last post by:
Is using fseek and ftell a reliable method of getting the file size on a binary file? I thought I remember reading somewhere it wasn't... If not what would be the "right" and portable method to...
6
by: Andrew Clark | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** Hello all, I recall several threads over the years about how reading file size cannot be done consistantly or portably, but I...
49
by: Sam | last post by:
Hi all, Is there a function in the standard library that can get the size of a file? Thank you very much. Sam.
5
by: Claudio Grondi | last post by:
I have just started to play around with the bsddb3 module interfacing the Berkeley Database. Beside the intended database file databaseFile.bdb I see in same directory also the __db.001...
11
by: Parrot | last post by:
Is there any routine I can call to reduce the size of an image file after uploading a file from a client. I am looking to reduce file sizes programmatically using C# in my web page after uploading....
5
by: Jefferis NoSpamme | last post by:
Hi all, I'm trying to limit the file size of an image submission and I keep running into various problems. I've got most of it working, but I'm stumped and I have a basic question as to WHY this...
7
by: Adrián E. Córdoba | last post by:
Hi, there! I'm developing a little application which must record some events in a log file (.txt). How can I delete the first line in the log file every time I add a new line at the end, in order...
4
by: Doug | last post by:
Hi, It looks like the only way to get a size of a file within csharp is to use FileInfo and the Length property. However that only returns the number of bytes in the file which is translating...
1
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.