473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Checking Existence of File

I had a form like below that validated that a file was there before it
would submit.

<form name="attach" method="POST" action="run_this_pgm.cfm"
enctype="multipart/form-data" onSubmit="return(validateData(this))">
<input type="file" name="txtFileToUpload">
<input type="submit" name="btnAdd" value="Add" class="form_button">
</form>

function checkFile(frm)
{
var strLength = frm.txtFileToUpload.value.length;
var min = 5;
if (strLength < min)
{
alert("Please choose a valid file to upload.");
frm.txtFileToUpload.focus();
frm.txtFileToUpload.select();
return false;
}
}
function validateData(frm)
{
return (checkFile(frm))
}

I wanted to change it to submit in a popup window instead and not open
the new window unless a valid file exists. I made these changes below
but it does not work. Somehow I need to check the existence of the file
and not just that a string is in the textbox.

<form name="attach" method="POST" action="run_this_pgm.cfm"
enctype="multipart/form-data">
<input type="file" name="txtFileToUpload">
<button name="btnAdd" onclick="save_attach(this.form);">Add</button>
</form>

function save_attach(frm)
{
if ( validateData(frm) )
{
alert('should be ok');
}
}

Any help is appreciated.

Mike

Aug 9 '05 #1
2 2003
"mike" <hi****@charter.net> skrev i meddelandet
news:11**********************@f14g2000cwb.googlegr oups.com...
I had a form like below that validated that a file was there before it
would submit.

<form name="attach" method="POST" action="run_this_pgm.cfm"
enctype="multipart/form-data" onSubmit="return(validateData(this))">
<input type="file" name="txtFileToUpload">
<input type="submit" name="btnAdd" value="Add" class="form_button">
</form>

function checkFile(frm)
{
var strLength = frm.txtFileToUpload.value.length;
var min = 5;
if (strLength < min)
{
alert("Please choose a valid file to upload.");
Why should a file whose name is less than 5 characters long be deemed
invalid?
Not all operating systems use file type extensions.
frm.txtFileToUpload.focus();
frm.txtFileToUpload.select();
return false;
}
}
function validateData(frm)
{
return (checkFile(frm))
}

I wanted to change it to submit in a popup window instead and not open
the new window unless a valid file exists. I made these changes below
but it does not work. Somehow I need to check the existence of the file
and not just that a string is in the textbox.
The existence and integrity of the file is most reliably checked
server-side. And you need to do the checking anyhow. If the file did not
exist, no problem - you'll be able to find out very quickly server-side, and
returning an error message to the user should be quick and simple.

A scripting system that granted arbitrary "does a file by this name exist
somewhere" access to the user's local hard drive could tell you quite a lot
about the state of the user's system.
<form name="attach" method="POST" action="run_this_pgm.cfm"
enctype="multipart/form-data">
<input type="file" name="txtFileToUpload">
<button name="btnAdd" onclick="save_attach(this.form);">Add</button>
</form>

function save_attach(frm)
{
if ( validateData(frm) )
{
alert('should be ok');
}
}


You may be able to do this with nonstandard IE-only technologies. Watch for
more replies.

--
Joakim Braun
Aug 9 '05 #2


The type="file" input element is one that gives little access for
Security hazards, fairly you won't get many of those invalid calls, but
the checks you want to do, as indicated already, are done on the server,
on the server you do have access to the filesize and other properties of
the object, on the client, you do not due to security issues. And yes, in
IE you could by using an activeXObject but then again, that'll work only
for IE in Win32 only.

Danny

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Aug 9 '05 #3

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

Similar topics

4
by: GujuBoy | last post by:
i want to check to see if a certain program is installed on my windows box using python. how can i do that...(ie, i want to see if "word" is installed) please help
14
by: Leslaw Bieniasz | last post by:
Cracow, 3.01.2005 Hello, When opening a file stream in the append mode, either a new file is created (if a specified file does not exist), or an existing file is opened for adding stuff. Is...
1
by: Xeno Campanoli | last post by:
I'm having a hard time checking existence of windows. The only thing I found on this is page 224 of Rhino. Why is there no function to check this? Is there a publication on this part of the...
5
by: Richard L Rosenheim | last post by:
What's the proper technique for checking for the existence of an attribute within a node? Lets say I did a SelectSingleNode which returned this element: <AnAddress city="San Francisco"...
15
by: Geiregat Jonas | last post by:
is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); } a good way of checking if a file exists or not, if not how should I do it ?
2
by: John Smith | last post by:
1. Which is the best way to check the existence of a given directory using vb.net? .Net 1.1. 2. Which is the best way to check the existence of a given file using vb.net? .Net 1.1. Drive...
2
by: Anoop | last post by:
Hi All Please tell me how to check the existence of a file and the read permission to the file using python script Thanks for ur inputs Anoop
4
by: Patient Guy | last post by:
Does anyone have any coding rules they follow when doing argument checking? When arguments fail during check, do you return from the call with an ambiguous return value, or do you throw...
26
by: Army1987 | last post by:
Is this a good way to check wheter a file already exists? #include <stdio.h> #include <stdlib.h> int ask(const char *prompt); typedef char filename; int main(int argc, char *argv) { FILE...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.