473,786 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get image side via client side script before file uplaod

I need to get the size on an image client side before the client uploads it,
and if its too large, I need to alert the client rather than doing a
postback. The code below successfully writes the file size to the
text-input element on the second click (attempt), but writes -1 on the first
click. It must return the file size on the first click to be useable. Can
anyone explain why it returns -1 on the first click and then the actual file
size on the second click, and also can you provide a good solution to this?

Thanks!

<%@ Page Language="vb" AutoEventWireup ="false"
Codebehind="zzT estFileSize.asp x.vb" Inherits="Charm pix.zzTestFileS ize"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>zzTestFi leSize</title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="Visual Basic .NET 7.1" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">

</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">

<script language="javas cript" type="text/javascript">
function fromOnChange() {
var im;
im = new Image();
im.src = document.Form1. ctlFile.value;
document.Form1. txtTest.value = im.fileSize;
document.Form1. txtPath.value = im.src;
}
</script>

<INPUT type="file" id="ctlFile" name="ctlFile"> <INPUT type="button"
value="Button" onclick="fromOn Change()">
<INPUT type="text" id="txtTest"> <INPUT id="txtPath" type="text">
</form>
</body>
</HTML>



--
mo*******@nospa m.com
Nov 18 '05 #1
2 1580
You will need a client-side executable to do this, such as an ActiveX
control or Java Applet.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"moondaddy" <mo*******@nosp am.com> wrote in message
news:#P******** ******@TK2MSFTN GP11.phx.gbl...
I need to get the size on an image client side before the client uploads it, and if its too large, I need to alert the client rather than doing a
postback. The code below successfully writes the file size to the
text-input element on the second click (attempt), but writes -1 on the first click. It must return the file size on the first click to be useable. Can
anyone explain why it returns -1 on the first click and then the actual file size on the second click, and also can you provide a good solution to this?
Thanks!

<%@ Page Language="vb" AutoEventWireup ="false"
Codebehind="zzT estFileSize.asp x.vb" Inherits="Charm pix.zzTestFileS ize"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>zzTestFi leSize</title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="Visual Basic .NET 7.1" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">

</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">

<script language="javas cript" type="text/javascript">
function fromOnChange() {
var im;
im = new Image();
im.src = document.Form1. ctlFile.value;
document.Form1. txtTest.value = im.fileSize;
document.Form1. txtPath.value = im.src;
}
</script>

<INPUT type="file" id="ctlFile" name="ctlFile"> <INPUT type="button"
value="Button" onclick="fromOn Change()">
<INPUT type="text" id="txtTest"> <INPUT id="txtPath" type="text">
</form>
</body>
</HTML>



--
mo*******@nospa m.com

Nov 18 '05 #2
Hi Moondaddy,

AS for image 's "fileSize" return -1 problem, I suspect that whether it is
caused by the image object is not completely loaded. Based on my research
,the image object contains a member property called "complete" which
indicate whether the image has been completely loaded or not. So I think we
can put a "If..." statement before we get the image's fileSize for example

if(im.complete= = true)
{
alert(im.fileSi ze);
}

And here is a test page I've made and you can also have a test on your side
to see whether it works.
=============== ==aspx page=========== =========
<HTML>
<HEAD>
<title>CheckIma geSize</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
<script language="javas cript">
var im;
function loadImage()
{
im = new Image();
im.src = document.getEle mentById("imgUp loader").value;
}

function checkSize()
{
if(im!=null && im.complete == true)
{
alert(im.fileSi ze);
}
else
{
alert("not completely loaded!");
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>
<INPUT id="imgUploader " type="file" onpropertychang e="loadImage()" >
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<INPUT type="button" value="Check Image File Size"
onclick="checkS ize()">
</td>
</tr>
</table>
</form>
</body>
</HTML>
=============== ==========

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3

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

Similar topics

9
4340
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side vbscript reads the database and populates a listbox on the page with the first field from each record in the recordset. This works fine. - User selects an option on the listbox and, using the OnChange, I
6
30643
by: Ross M. Greenberg | last post by:
If I have a variable named 'fred', the contents looking like this: '/gif/picture1.gif', how can I display that image? Thanks! Ross
12
12433
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank, 'height=200,width=400,status=no,toolbar=no, menubar=no,location=no resizable=no scrollable=no'); but I can't seem to invoke the client side script from within a Server Side Form. I know I can use the context with to Response.redirect or Server.transfer to return a
6
3537
by: Olly | last post by:
I've found a basic script, however I also need to add alt and title attributes as well, how would I go about doing this? Here's the script I found: Thanks <script language="JavaScript"> <!-- /*
26
15310
by: Don | last post by:
I'm writing an html page with some JavaScript that reads a web page into a client-side temp file, then reformats it, then submits that same file as a URL to the browser for display, via "locate.replace". I can do all this if the html page containing the script originates on the client machine, but don't know how to get access to a client-side temp file when the same html page containing the script is on a web host. How do I get access...
3
6750
by: coolsti | last post by:
I need some help here. I am making an application which allows a user to look at a series of picture files one at a time, and enter the outcome of various visual tests to a database. The application is based on mysql and php on a remote server, and is accessed by the user via a web browser, primarilly IE. The image file names are built up by the server side php scripts, and so a URL for the image file is created, but the file itself is...
17
2166
by: HornyLaBelle | last post by:
I'm hiding the email address on a website with this javascript which works fine: --------------------------------- <p>Send your comments and questions to our <script language=javascript> <!-- var contact = "Newsletter Editor"
11
1896
by: Adam Sandler | last post by:
Hello, Having an issue with JavaScript in my ASP.Net page. I use some COTS, which for all intents and purposes, simply makes a jpeg file and physically places it in a directory on the web server. The page load codebehind, makes a connection to the jpeg creation service and gets the path of the newly created image.
32
3143
by: C. (http://symcbean.blogspot.com/) | last post by:
Hi all, I have an application which generates image graphs. These cache nicely at the client, however if the user submits more data, I'd like to force a reload of the image from the server. I had a google, but all I could find were suggestions to use a varying query in the URL. This is not a solution to my problem because if I change the page to do that then ALL the graphs will be reloaded every time.
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9961
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
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
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
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4066
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
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.