473,549 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_thi s_pgm.cfm"
enctype="multip art/form-data" onSubmit="retur n(validateData( this))">
<input type="file" name="txtFileTo Upload">
<input type="submit" name="btnAdd" value="Add" class="form_but ton">
</form>

function checkFile(frm)
{
var strLength = frm.txtFileToUp load.value.leng th;
var min = 5;
if (strLength < min)
{
alert("Please choose a valid file to upload.");
frm.txtFileToUp load.focus();
frm.txtFileToUp load.select();
return false;
}
}
function validateData(fr m)
{
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_thi s_pgm.cfm"
enctype="multip art/form-data">
<input type="file" name="txtFileTo Upload">
<button name="btnAdd" onclick="save_a ttach(this.form );">Add</button>
</form>

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

Any help is appreciated.

Mike

Aug 9 '05 #1
2 2023
"mike" <hi****@charter .net> skrev i meddelandet
news:11******** **************@ f14g2000cwb.goo glegroups.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_thi s_pgm.cfm"
enctype="multip art/form-data" onSubmit="retur n(validateData( this))">
<input type="file" name="txtFileTo Upload">
<input type="submit" name="btnAdd" value="Add" class="form_but ton">
</form>

function checkFile(frm)
{
var strLength = frm.txtFileToUp load.value.leng th;
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.txtFileToUp load.focus();
frm.txtFileToUp load.select();
return false;
}
}
function validateData(fr m)
{
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_thi s_pgm.cfm"
enctype="multip art/form-data">
<input type="file" name="txtFileTo Upload">
<button name="btnAdd" onclick="save_a ttach(this.form );">Add</button>
</form>

function save_attach(frm )
{
if ( validateData(fr m) )
{
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
5127
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
5078
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 there any way to determine, after calling the open(filename,ios::app) method, which of these two alternatives has occurred? I would like to...
1
1480
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 protocol I can read as a newbie? Please can someone make a suggestion one what to read or try? Sincerely, Xeno -- Community FIRST, Then Trade!...
5
19523
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" state="CA" /> What's the best why of determining if the attribute zipcode exists in this node? If I try accessing the attribute with code like: ZipCode...
15
114182
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
4935
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 includes mapped network drive also. Thank you,
2
518
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
2362
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 exceptions?
26
4924
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 *in, *out;
0
7464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7979
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...
0
7826
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...
0
6065
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...
0
3512
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...
0
3493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1960
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
1
1074
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
781
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...

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.