I have developed an upload tool, that allows users to upload files (funny
that). The asp form object has a 'SizeLimit' property that can be set, to
prevent files being uploaded, that are too large. Is there a way in
Javascript, to interrogate the file size before the form is posted, so that
the validation can be done before trying to post the form.
The only information I can find, on file size, relates to images. But any
file can be uploaded through this tool, so I also need to determine the size
of other binary and text files. 2 4728
Ruskin wrote: I have developed an upload tool, that allows users to upload files (funny that). The asp form object has a 'SizeLimit' property that can be set, to prevent files being uploaded, that are too large. Is there a way in Javascript, to interrogate the file size before the form is posted, so that the validation can be done before trying to post the form.
The only information I can find, on file size, relates to images. But any file can be uploaded through this tool, so I also need to determine the size of other binary and text files.
Hi,
As far as I know: No. You cannot.
Javascript is intentionally crippled when it come to local file, for obvious
securityreasons .
Maybe clientside VB-script can: VB is well known for such 'features'.
I am unsure.
Anyway, that would limit your your clients to browsers that support
VB-script, not a wise choice. :-(
Regards,
Erwin Moller
Erwin Moller wrote: Javascript is intentionally crippled when it come to local file, for obvious securityreasons .
No, the browser DOM is intentionally crippled when it comes to local files.
JavaScript itself has no way of accessing files at all.
This is more than just nitpicking. JavaScript itself can contain security
vulnerabilities , for example I vaguely remember some Array or String overflow
vulnerability in early versions of JavaScript, where a specially constructed
Array or String could result in code execution.
But the more importantly, the DOM that JavaScript (or VBScript or PerlScript or
AnyScript) accesses can contain security vulnerabilities , and that is where most
of the problems appear.
Maybe clientside VB-script can: VB is well known for such 'features'. I am unsure.
There is no difference between the things that can be done in Internet Explorer
between JavaScript and VBScript (well, there are differences, but not in terms
of the security implications you are referring to). In other words, the security
vulnerabilities are in the DOM and the ActiveX components, not really in the
scripting language itself.
If you can instanciate a FileSystemObjec t in VBScript and manipulate local
files, you can instanciate a FileSystemObjec t in JavaScript and manipulate local
files.
Anyway, that would limit your your clients to browsers that support VB-script, not a wise choice. :-(
The choice would be between a user agent that support an object with properties
and methods capable of accessing the local file system, and using a user agent
that does not.
However, a solution to his question has already been provided (at least in
Internet Explorer):
<form name="myForm">
<input type="file" name="myFile">
<script type="text/javascript">
if ((new Image()).fileSi ze) {
document.write(
'<input type="button"' +
' name="mySize" value="Show Size"' +
' onclick="showSi ze(this.form);" >'
);
}
function showSize(f) {
if ((new Image()).fileSi ze) {
var img = new Image();
img.onload = imgOnload;
img.onerror = imgOnerror;
img.src = f.elements['myFile'].value;
}
}
function imgOnload() {
if (this.fileSize) {
var size = this.fileSize;
if (size > 1024) {
size = Math.round((siz e / 1024) * 100) / 100;
}
alert(
'The file is ' + size +
(this.fileSize > 1024 ? ' kilobytes' : ' bytes') +
' in size.'
);
}
}
function imgOnerror() {
alert('The file is not an image or did not load.');
}
</script>
</form>
--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave Smithz |
last post by:
Hi There,
I have a PHP script that sends an email with attachment and works great when
provided the path to the file to send.
However this file needs to be on the same server as the script.
I want to develop a webpage where people can send attachments that are
stored on their local PC.
|
by: M P |
last post by:
Can you help me find an asp code that will upload a file from my PC to web
server?
Mark
|
by: Skc |
last post by:
I have a .txt which has been exported as a .csv from an external source.
What i need to do is to import this into SQL2000 (into a table) but I need to
do special things on the data:
1. I need to look for the first three chars and import rows into separate
tables. E.g. if the first three chars begin with CCC, then this row goes
into the CCC_table, if it is TTT then into the TTT_table etc...
2. Once I have my tables built up, I need to do...
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen. It is
almost like it is trying to implement it's own COM interfaces...
below is the header, and a link to the dll+code:
Zip file with header, example, and DLL:...
|
by: BW |
last post by:
I am creating an upload/download function for an extranet site. Files will
be uploaded to directory based upon the users login and associated project.
The function works as long as I use "c:\Temp" as the directory. When I use
any other hard coded directory or even Server.MapPath() the upload function
fails and returns the error: "Exception has been thrown by the target of an
invocation." Once I change the root directory to "c:\Temp",...
| |
by: Dan |
last post by:
Hi,
I know this code is not entirely javascript, but bare with me. Can you
please tell me why this does not work:
page: filemanager.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
|
by: j7.henry |
last post by:
I am trying to pull specific data that is in a comma delimited file
into a web page. So if my comma delimited file looks like:
Name,Address,Zip
Fred,123 Elm,66666
Mike,23 Jump,11111
I would like to be able to read this data and put each row into a
variable? so I could display the values in a web page where I want.
|
by: forest demon |
last post by:
for example, let's say I do something like,
System.Diagnostics.Process.Start("notepad.exe","sample.txt");
if the user does a SaveAs (in notepad), how can i capture the path that
the user selects?
thanks...
|
by: cleary1981 |
last post by:
Hi, I have created a script in PHP thats generates an SVG image. Want I want to do is have PHP save this as example.svg. Can this be done? Heres my code
<?php
require "config.php";
$proj_id = $_GET;
//set the content type
header("Content-type: image/svg-xml");
|
by: premprakashbhati |
last post by:
hi, good evening..
i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button()
here is the code ...its work fine when iam using a normal web page... but can't in content page....
Code in Master Page
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="submaster.master.cs" Inherits="submaster" %>
<%@ Register Assembly="AjaxControlToolkit"...
|
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...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
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();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |