Znalazłem coś takiego gdzieś na stronach - javscript sprawdza format pliku - i wszystko działa jezeli jest tylko jeden input...
no i tu jest mały problem... jeżeli będą np. dwa:
<input type=file name=uploadfile[]>
To nic nie działa (IMG:
http://forum.php.pl/style_emoticons/default/sad.gif) ...
Czy jest jakiś sposób żeby to zadziałało?
(wiem jak to zrobić w php - ale zależy mi żeby sprawdzić to z alertem po stronie przeglądarki)
<script LANGUAGE="JavaScript"> <!-- Begin
extArray = new Array(".gif", ".jpg", ".png");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) form.submit();
else
alert("Please only upload files that end in types: "
+ (extArray.join(" ")) + "\nPlease select a new "
+ "file to upload and submit again.");
}
// End -->
Please upload only images that end in:
document.write(extArray.join(" "));
<form method=post name=upform action="/cgi-bin/some-script.cgi" enctype="multipart/form-data"> <input type=file name=uploadfile> <input type=button name="Submit" value="Submit" onclick="LimitAttach(this.form, this.form.uploadfile.value)">