M
moondaddy
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="zzTestFileSize.aspx.vb" Inherits="Charmpix.zzTestFileSize"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>zzTestFileSize</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<script language="javascript" 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="fromOnChange()">
<INPUT type="text" id="txtTest"> <INPUT id="txtPath" type="text">
</form>
</body>
</HTML>
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="zzTestFileSize.aspx.vb" Inherits="Charmpix.zzTestFileSize"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>zzTestFileSize</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<script language="javascript" 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="fromOnChange()">
<INPUT type="text" id="txtTest"> <INPUT id="txtPath" type="text">
</form>
</body>
</HTML>