Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

occassionally occuring problem

Status
Not open for further replies.

WebRic

Technical User
Sep 21, 2004
95
GB
Hi All,

I have a problem regarding getting the files size of an image.

Sometimes this script detects the image size other times it doesn't. I can select the same image without reloading the page and occasionaly it won't give the file size.

It's really trciky to figure out. Any advice on how to track the problem of any ways of writting the code better would be great.
Code:
		x=new Image;
		x.src=element.value;
		
		iw=x.width;
		nw=100/x.width
		ih=x.height;
		nh=nw*ih;
		is=Math.ceil(x.fileSize/1000);

		// Set row value
		new_row.innerHTML = '<img src="file:///'+element.value+'" width="100" height="'+nh+'" />';
		
		// Add the file sizes
		if(isNaN(is) != true) {
		thesize = document.getElementById('uploadSize')
		oldsize = parseInt(thesize.value,10);
		thesize.value = oldsize + is;
		document.getElementById('upload_size').innerHTML = thesize.value;
					}

Thanks,

Richard
 
Have a look at my FAQ, "Detecting the dimensions of an image client-side" (faq216-5781). Notice that I wait for the image to load before trying to determine any of its properties.

I'd advise going down this route with your code.

Also, you should note that the "fileSize" property is non-standard, and is probably not supported by any browser other than IE (although you'd need to test this).

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I've had another urgent project that needed my attention, and haven't had a chance to implement this. I'm hoping to get a chance to look at this Monday next week.

I'll let you know how I get on.
Thanks,

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top