473,890 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FileSize - image

Ken
I would like to measure the fileSize of the image (without uploading it -
php).

I use:
var size_pic = document.getEle mentById('num1' ).childNodes[0].fileSize;
alert("size = " + size_pic);
which works on IE with one exception.

With a first time displayed image, the script displays a size= -1 The image
is displayed on the first pass. The fileSize script is located after the
img script.
var image_display=d ocument.createE lement('img');
image_display.s rc='file://' + field;
image_display.n ame = 'pict';
document.getEle mentById('num1' ).appendChild(i mage_display);

The second pass is correct. size = 11479

Is this a cache problem? The first pass caches the file, the second pass
reads the file?

I tried running - var size_pic
=document.getEl ementById('num1 ').childNodes[0].fileSize; - twice but that
made no difference.

Is there a work around for this problem.

Is there a better way to measure filesize in JavaScript?

Have a good day!

Ken
Jul 23 '05 #1
4 5470
Ken wrote:
I would like to measure the fileSize of the image (without uploading it -


You asked this question a couple of weeks ago, the answer is still the
same - you can't. Read your thread of 9 Oct.

Zif.
Jul 23 '05 #2
Ken wrote:
I would like to measure the fileSize of the image (without uploading it -
php).

I use:
var size_pic = document.getEle mentById('num1' ).childNodes[0].fileSize;
alert("size = " + size_pic);
which works on IE with one exception.

With a first time displayed image, the script displays a size= -1 The image
is displayed on the first pass. The fileSize script is located after the
img script.
var image_display=d ocument.createE lement('img');
image_display.s rc='file://' + field;
image_display.n ame = 'pict';
document.getEle mentById('num1' ).appendChild(i mage_display);

The second pass is correct. size = 11479

Is this a cache problem? The first pass caches the file, the second pass
reads the file?


No, the problem is that the file has not yet loaded by the time you attempt to
access it's size. Make the display of it's size dependant on the onload event of
the image.

var image_display=d ocument.createE lement('img');
image_display.o nload = function() {
alert(this.file Size);
}
image_display.s rc='file://' + field;
image_display.n ame = 'pict';
document.getEle mentById('num1' ).appendChild(i mage_display);

Of course, you'll need to replace alert(this.file Size) with something more
useful, perhaps create another node under the image and display the size there.

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #3
Ken
"Grant Wagner" <gw*****@agrico reunited.com> wrote in message
news:41******** *******@agricor eunited.com...
Ken wrote:
I would like to measure the fileSize of the image (without uploading it - php).

I use:
var size_pic = document.getEle mentById('num1' ).childNodes[0].fileSize;
alert("size = " + size_pic);
which works on IE with one exception.

With a first time displayed image, the script displays a size= -1 The image is displayed on the first pass. The fileSize script is located after the img script.
var image_display=d ocument.createE lement('img');
image_display.s rc='file://' + field;
image_display.n ame = 'pict';
document.getEle mentById('num1' ).appendChild(i mage_display);

The second pass is correct. size = 11479

Is this a cache problem? The first pass caches the file, the second pass reads the file?
No, the problem is that the file has not yet loaded by the time you

attempt to access it's size. Make the display of it's size dependant on the onload event of the image.

var image_display=d ocument.createE lement('img');
image_display.o nload = function() {
alert(this.file Size);
}
image_display.s rc='file://' + field;
image_display.n ame = 'pict';
document.getEle mentById('num1' ).appendChild(i mage_display);

Of course, you'll need to replace alert(this.file Size) with something more
useful, perhaps create another node under the image and display the size there.
--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Grant,
Thanks for the suggestion.
Works great.
Ken


Jul 23 '05 #4
Ken
"Grant Wagner" <gw*****@agrico reunited.com> wrote in message
news:41******** *******@agricor eunited.com...
Ken wrote:
I would like to measure the fileSize of the image (without uploading it - php).

I use:
var size_pic = document.getEle mentById('num1' ).childNodes[0].fileSize;
alert("size = " + size_pic);
which works on IE with one exception.

With a first time displayed image, the script displays a size= -1 The image is displayed on the first pass. The fileSize script is located after the img script.
var image_display=d ocument.createE lement('img');
image_display.s rc='file://' + field;
image_display.n ame = 'pict';
document.getEle mentById('num1' ).appendChild(i mage_display);

The second pass is correct. size = 11479

Is this a cache problem? The first pass caches the file, the second pass reads the file?
No, the problem is that the file has not yet loaded by the time you

attempt to access it's size. Make the display of it's size dependant on the onload event of the image.

var image_display=d ocument.createE lement('img');
image_display.o nload = function() {
alert(this.file Size);
}
image_display.s rc='file://' + field;
image_display.n ame = 'pict';
document.getEle mentById('num1' ).appendChild(i mage_display);

Of course, you'll need to replace alert(this.file Size) with something more
useful, perhaps create another node under the image and display the size there.
--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Grant,

This works but not like I want.

I am trying to determine the file size to test for size < max spec. The
script works for the first image but not for a second image which replaces
the first image if it is over spec.

Removing the onload... the script works but will not measure fileSize on the
first pass.

Any suggestions.

Ken

<input type=file size=65 name="picture1" onChange="image _size(this.valu e);"
Id="pt1">
<div id="image_size_ display"></div>
<script type="text/javascript">
// Image size to be under max limit
function image_size(fiel d){
if ((document.crea teElement) && (document.getEl ementById)) {
var image_display=d ocument.createE lement('img');
image_display.o nload = function() { image_size = this.fileSize; }
image_display.s rc='file://' + field;
image_display.n ame = 'pict';
image_display.a lt = 'image';

document.getEle mentById('image _size_display') .appendChild(im age_display);

alert("image_si ze = " + image_size);

if(image_size >2000000){alert ("This picture ( file ) is geater than
2,000,000.\n\n" + "Select another picture or reduce the size of the picture
( file )")};
alert("test");

document.getEle mentById('image _size_display') .removeChild(im age_display);
} }
</script>
Jul 23 '05 #5

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

Similar topics

0
2273
by: Phil Powell | last post by:
// PROCESS XML CONTENT INTO DYNAMICALLY-NAMED ARRAYS foreach (array('mime', 'state', 'country') as $val) { $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, ${$val . 'XML'}, ${$val . 'XMLArray'}, $tags); xml_parser_free($parser); $myXMLArray = ${$val . 'XMLArray'}; for ($i = 1; $i < @sizeof($myXMLArray) - 1; $i++) { if ($myXMLArray) {
6
3315
by: John | last post by:
Hi all, I'd like to evaluate dynamicaly the size of a dynamic file. I use the filesize() function... this is my code : $my_size = filesize(http://localhost/the_file_from_which_i_want_to_get_the_size.php) ; => I always get 0 !
4
2640
by: Marek Möhling | last post by:
My server (Apache/1.3.28 - PHP/4.3.3) is configured to receive gzipped data via: Header append Accept-Encoding "gzip, deflate" PHP is configured to send gzipped data via: php_value output_handler ob_gzhandler When downloading files from servers that send gzipped data as well, I'd like to get the filesize before and after my server decompresses them.
5
1648
by: David | last post by:
Not sure whether this is something Im doing wrong or just something the filesize() function doesnt support but... <? $fsize1 = filesize("foo.txt"); $fp = fopen("foo.txt",a); $time = time(); fputs($fp,$time); fclose($fp); $fsize2 = filesize("foo.txt");
2
11704
by: IWP506 | last post by:
I just CANNOT figure out what is wrong with this! ------ $op1f = fopen("./test.txt","r"); $op1 = fread($op1f, filesize($op1f)); ------
3
3396
by: Arjen | last post by:
Hello, When I have read a file with x.xxx.xxx.xxx bytes it is sometimes handy to show it in an diverent format than bytes. Is there a handy way to do this? Or is there a function for it? When it is a big file I want to see a MB size and when it is a lower file size then I want to see a kB size for example.
3
4380
by: mosscliffe | last post by:
I get a list of filenames from a directory with the following code, but I can not work out how to get the filesize of the filename I have just found. I guess it is fileinfo.length, but I can not see how to turn my filename(string) into a statement which would give me the filesize - the brain is very slow today. Any help gratefully appreciated. Dim files() As String = System.IO.Directory.GetFiles(root, patt)
2
4676
by: Eric Layman | last post by:
I have checked this setting in my php.ini allow_url_fopen = On It is ON be default. According to the PHP documentation: it stated that as of php5, filesize supports the reading of remote html files:
3
2627
ganesanji
by: ganesanji | last post by:
hi all, I have created a simple downloading script for a file which is given below$f="images/52219-4.bmp"; $ftype = mime_content_type($f); $fsize= filesize($f); header("Content-type: \"".$ftype."\""); header("Content-Disposition: attachment; filename=\"".$f."\""); header("Content-length:".$fsize); readfile($f); exit; Even this script downloads the image, the downloaded file size is 0 bytes.
0
9976
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
11214
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10903
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,...
0
10449
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5834
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...
0
6034
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4659
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
3
3266
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.