Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> jak sprawdzić format pliku przed wysłaniem...?
kpiotrek
post
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 14.06.2004

Ostrzeżenie: (0%)
-----


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:
  1. <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)

  1. <HEAD>
  2.  
  3. <script LANGUAGE="JavaScript">
  4. <!-- Begin
  5. extArray = new Array(".gif", ".jpg", ".png");
  6. function LimitAttach(form, file) {
  7. allowSubmit = false;
  8. if (!file) return;
  9. while (file.indexOf("\\") != -1)
  10. file = file.slice(file.indexOf("\\") + 1);
  11. ext = file.slice(file.indexOf(".")).toLowerCase();
  12. for (var i = 0; i < extArray.length; i++) {
  13. if (extArray[i] == ext) { allowSubmit = true; break; }
  14. }
  15. if (allowSubmit) form.submit();
  16. else
  17. alert("Please only upload files that end in types: "
  18. + (extArray.join(" ")) + "\nPlease select a new "
  19. + "file to upload and submit again.");
  20. }
  21. // End -->
  22. </script>
  23. </HEAD>
  24.  
  25. <BODY>
  26.  
  27. Please upload only images that end in:
  28. document.write(extArray.join(" "));
  29. </script>
  30. <p>
  31.  
  32. <form method=post name=upform action="/cgi-bin/some-script.cgi" enctype="multipart/form-data">
  33. <input type=file name=uploadfile>
  34. <p>
  35. <input type=button name="Submit" value="Submit" onclick="LimitAttach(this.form, this.form.uploadfile.value)">
  36. </form>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 23:56