473,385 Members | 1,409 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,385 software developers and data experts.

file upload checking

im trying to do file extension checking but its not working :(

i have the following in the head

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2.     extArray = new Array(".jpg", ".png", ".bmp");
  3.     function LimitAttach(form, file) {
  4.     allowSubmit = false;
  5.     if (!file) return;
  6.     while (file.indexOf("\\") != -1)
  7.     file = file.slice(file.indexOf("\\") + 1);
  8.     ext = file.slice(file.indexOf(".")).toLowerCase();
  9.     for (var i = 0; i < extArray.length; i++) {
  10.     if (extArray[i] == ext) { allowSubmit = true; break; }
  11.     }
  12.     if (allowSubmit) return true;
  13.     else
  14.     alert("Please only upload files that end in types:  "
  15.     + (extArray.join("  ")) + "\nPlease select a new "
  16.     + "file to upload and submit again.");
  17.     return false;
  18.     }
  19.     //  End -->
  20. </script>
this is the html code
the {} are things inserted via php
i believe it is something to do with the onclick

[HTML] <form name="upload" action="{THIS}" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="6510200">
<input type="hidden" name="op" value="upload" />
<input type="hidden" name="dir" value="{NEXT_DIR}" />
<table border="0" width="100%" cellpadding="1">
<tr class="task_cell">
<td width="5%" nowrap="nowrap"><b>{LOCAL}</b>&nbsp;</td>
<td width="70%"><input type="file" name="local" size="45" style="width: 90%" onchange="javascript:filename();" /></td>
<td valign="bottom" align="right"><input onclick="javascript: window.location.href = '{MULTI_UPLOAD}?dir={NEXT_DIR}';" type="button" value="{MULTIPLE}" /></td>
</tr>
<tr class="task_cell">
<td width="5%" nowrap="nowrap"><b>{UPNAME}</b>&nbsp;</td>
<td width="70%"><input type="text" name="remote" size="45" style="width: 90%" /></td>
<td align="right" valign="bottom"><input onclick="javascript: return isValid(); return LimitAttach(this.form, this.form.local.value);" type="submit" value="{UPLOAD}" /></td>
</tr>
</table>
</form>[/HTML]

if anyone knows whats wrong please help, i will even pay you if you dont need too much as my site cant survive atm without it :)

[HTML]<input onclick="javascript: return isValid(); return LimitAttach(this.form, this.form.local.value);" type="submit" value="{UPLOAD}" /> [/HTML]

is most likley where im going wrong
May 5 '06 #1
1 4843
acoder
16,027 Expert Mod 8TB
LimitAttach will never run because there is already a return when calling isValid(). Either put both in a separate function and call that or change the return into an if-else statement, so if it's valid, LimitAttach is called, e.g.[HTML]<input onclick="if (isValid()) return LimitAttach(this.form, this.form.local.value); else return false;" type="submit" value="{UPLOAD}" /> [/HTML]It's better calling this from form onsubmit rather than submit button onclick.
Apr 21 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Amy Kimber | last post by:
Hello all, ok, I have a file upload secton to my site, two pages, one with a form and one that does the uploading.... some files upload fine, other don't an exe of 300k will upload, but a...
1
by: Jonathan | last post by:
Hi everyone, I have a problem with the file uploading in Asp.Net and I have read a lot on forums on this but never found an answer. Here is the problem: I know Asp.Net maximum Length for...
6
by: Thomas Due | last post by:
Hi, I am writing an ASP.NET project where I allow users to upload files to the server. I have changed to web.config to allow a total file size of 100MB. My problem is that if the total file size...
14
by: Al Smith | last post by:
I need help in implementing proper error handling. I am trying to upload a file based on the sample code below. The code works well except if the file selected is too big. I do know about the...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
5
by: William LaMartin | last post by:
I have a VB ASP.Net application where the user can upload a file using the FileUpload server control. I also want a thumbnail to be created for this file. Unfortunately I can see no means to...
19
by: jeremyz | last post by:
Hi all, I am not a developer, but I work with several and am posting this for them. We are trying to determine whether it is possible to check the size of a file before a user uploads it. ...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
2
by: jeddiki | last post by:
Hello, Hopefully I can do this with php I want to allow my clients to upload their pdf or video files to my server without giving them ftp login details. Lets look at PDF's first: This...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.