免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6099 | 回复: 2
打印 上一主题 下一主题

JavaScript中执行文件上传,该调用哪个函数? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-04-27 10:15 |只看该作者 |倒序浏览
请问大家,JavaScript中有没有函数是用来执行文件上传的,是哪个函数?

在此先谢谢了!!

论坛徽章:
0
2 [报告]
发表于 2005-04-27 14:41 |只看该作者

JavaScript中执行文件上传,该调用哪个函数?

各位大大,来顶一下阿!!!!!!

论坛徽章:
0
3 [报告]
发表于 2005-04-28 09:01 |只看该作者

JavaScript中执行文件上传,该调用哪个函数?

Allowing visitors to upload files through web forms on your site is useful, but how do you limit the types of files they can upload? This script only allows visitors to upload files that end with the file extensions you want, such as .gif and .jpg, etc. Easy!


  1. <!-- TWO STEPS TO INSTALL UPLOAD FILTER:

  2.   1.  Copy the coding into the HEAD of your HTML document
  3.   2.  Add the last code into the BODY of your HTML document  -->;

  4. <!-- STEP ONE: Paste this code into the HEAD of your HTML document  -->;

  5. <HEAD>;

  6. <SCRIPT LANGUAGE="JavaScript">;
  7. <!-- Original:  ArjoGod, Shauna Merritt -->;
  8. <!-- Modified By:  Ronnie T. Moore, Editor -->;

  9. <!-- This script and many more are available free online at -->;
  10. <!-- The JavaScript Source!! http://javascript.internet.com -->;

  11. <!-- Begin
  12. extArray = new Array(".gif", ".jpg", ".png");
  13. function LimitAttach(form, file) {
  14. allowSubmit = false;
  15. if (!file) return;
  16. while (file.indexOf("\\") != -1)
  17. file = file.slice(file.indexOf("\\") + 1);
  18. ext = file.slice(file.indexOf(".")).toLowerCase();
  19. for (var i = 0; i < extArray.length; i++) {
  20. if (extArray[i] == ext) { allowSubmit = true; break; }
  21. }
  22. if (allowSubmit) form.submit();
  23. else
  24. alert("Please only upload files that end in types:  "
  25. + (extArray.join("  ")) + "\nPlease select a new "
  26. + "file to upload and submit again.");
  27. }
  28. //  End -->;
  29. </script>;
  30. </HEAD>;

  31. <!-- STEP TWO: Copy this code into the BODY of your HTML document  -->;

  32. <BODY>;

  33. <center>;
  34. Please upload only images that end in:  
  35. <script>;
  36. document.write(extArray.join("  "));
  37. </script>;
  38. <p>;

  39. <form method=post name=upform action="/cgi-bin/some-script.cgi" enctype="multipart/form-data">;
  40. <input type=file name=uploadfile>;
  41. <p>;
  42. <input type=button name="Submit" value="Submit" onclick="LimitAttach(this.form, this.form.uploadfile.value)">;
  43. </form>;
  44. </center>;

  45. <p>;<center>;
  46. <font face="arial, helvetica" size="-2">;Free JavaScripts provided<br>;
  47. by <a href="http://javascriptsource.com">;The JavaScript Source</a>;</font>;
  48. </center>;<p>;

  49. <!-- Script Size:  1.55 KB -->;
复制代码

untitled.jpg (5.92 KB, 下载次数: 161)

效果图

效果图
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP