473,326 Members | 2,805 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,326 software developers and data experts.

File Size

Ken
Can JavaScript detect the size of an image file?

Ken

Jul 23 '05 #1
2 2712
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.