怎样检测上传文件的大小?

linuxpig 2003-08-30 01:36:30
用javascript作了一个页面,是用来检测上传文件大小的,怎样写这个程序?

请指教!




礼!
...全文
52 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
JYJUN 2003-11-06
  • 打赏
  • 举报
回复
我用wanghr100(灰豆宝宝.net) 的方法试验,运行时提示错误:

错误:Automation服务器不能创建对象

请各位赐教如何解决。
多谢!!!
aocool 2003-10-17
  • 打赏
  • 举报
回复
<SCRIPT language=javascript>
function index_image_valid(){
var img=new Image();
img.src=document.pho_up.pho_index.value;
imagewidth=img.width;
imageheigth=img.height;
fsize=img.fileSize/1024;
fsize=fsize.toFixed(1);
document.pho_up.cmd.disabled=true;
if(img.readyState!="complete")
window.setTimeout("index_image_valid()",10);
else
{alert ("宽:"+imagewidth+"\n高:"+imageheigth+"\n大小:"+fsize+" KB");
document.pho_up.cmd.disabled=false}
}
</script>
</head>
<form name="pho_up" method="post" enctype="multipart/form-data">
<input type="file" name="pho_index" size="20">
<input type=button name="cmd" value="测试图片大小" onclick="index_image_valid();">
</form>
wanghr100 2003-08-30
  • 打赏
  • 举报
回复
有安全提示的.

<HTML><HEAD>
<SCRIPT>

function getFileSize (fileName) {

if (document.all) {
window.oldOnError = window.onerror;
window.onerror = function (err) {
if (err.indexOf('utomation') != -1) {
alert('没有访问文件的权限');
return true;
}
else
return false;
};
var fso = new ActiveXObject('Scripting.FileSystemObject');
var file = fso.GetFile(fileName);
window.onerror = window.oldOnError;
return file.Size; }}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName"><INPUT TYPE="file" NAME="fileName"><BR>
<INPUT TYPE="button" VALUE="查看文件字节大小" ONCLICK="alert(getFileSize(this.form.fileName.value)+'字节')"><BR>
</FORM></BODY>
</HTML>
Debian 2003-08-30
  • 打赏
  • 举报
回复
对于IE就用FileSystemObject,
对于mozilla,netscape以及Mozilla based browser,惭愧.......

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧