PDA

View Full Version : Upload Only some files



Baleric
Jan 24th, 2007, 12:29 AM
hey guys, im using FREEASPUPLOAD to upload files and was wondering if i can restrict certain files from being uploaded, or even better, only allow certain files
like .rar and .zip

i have this information if it helps


The upload page has a form validation JavaScript function ("onSubmitForm")
where you can add that test. The filename can be accessed in that function
through "formDOMObj.attach1.value".



the submit on the form is onSubmit="return onSubmitForm();

my javascript skills are shocking and any help would bne greatly appreciated,

cheers

Baleric

david_kw
Jan 24th, 2007, 08:38 AM
My regular expression skills are lacking so hopefully someone else will say if this is wrong. But try adding this to near the end of onSubmitForm(). Before any return(true); statement.



if (!(/\.(zip|rar)$/.test(formDOMObj.attach1.value))) {
return(false);
}


david_kw

Kor
Jan 24th, 2007, 10:36 AM
A variant:



function onSubmitForm(thisForm){
if (!(/\.(zip|rar)$/.test(thisForm['attach1'].value))) {
return false;
}
}
.......
<form onsubmit=return onSubmitForm(this)>

Baleric
Jan 24th, 2007, 09:48 PM
hi guys,
it didnt work :P
i loaded up a jpeg and nothing...

should it be?

function onSubmitForm(thisForm)
if (!(/\.(zip|rar)$/.test(thisForm['attach1'].value))) {
return false;
}
}
.......
<form onsubmit=return onSubmitForm(thisForm)>

or jsut this?

i tryed it with thisform and it didnt work also,

thanks again so far

baleric

david_kw
Jan 24th, 2007, 10:55 PM
It should be just this and there wa a curly brace missing which can be seen below in red.




function onSubmitForm(thisForm) {
if (!(/\.(zip|rar)$/.test(thisForm['attach1'].value))) {
return false;
}
}
.......
<form onsubmit=return onSubmitForm(this)>


One thing to remember is if javascript is turned off this validation will not work and the user can upload whatever they want.

david_kw

Baleric
Jan 27th, 2007, 09:14 AM
thanks alot guys,
works great!!!

i added an alert in too :D

thats probably the only thing i know how to do in JS

thanks again dave.