>
设为首页
>
收藏本站
>
最新电影
首页
运营资讯
今日英语
图形图像
计算机技术
Asp编程
网站结构化
资源共享
休闲娱乐
访问新站
您现在的位置:
首页
=>
后台技术
=>
脚本特效
=>
页面特效
订阅本栏目
图片上传预览,可显示文件大小,宽、高
时间: 2008-10-21 10:35:03 阅读次数:2824
图片上传预览,可显示文件大小,宽、高
<HTML> <HEAD> <title>Upload Image</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </HEAD> <STYLE type="text/css"> * {font-size:9pt;font-family:SimSun} body {margin:0px;overflow:hidden} #upfile {width:100%} #preview {width:100%;height:100%;overflow:hidden;background-color:#808080;margin:auto} #pv {display:none} </STYLE> <script language="JScript"> var obImg = new Image(); var validExt = ".jpg|.jpeg|.gif|.bmp|.png|"; var bOK = false; function ShowInfo(sInfo) { document.all["info"].innerText = sInfo; } function CheckProperty() { if(obImg.readyState != "complete") { setTimeout("CheckProperty()",500); return; } bOK = true; var iImgSize = Math.round(obImg.fileSize / 1024 * 100) / 100; ShowInfo("图片大小:" + iImgSize + " KB 图片尺寸:" + obImg.width + " x " + obImg.height); var iContentWidth = document.all["preview"].offsetWidth; var iContentHeight = document.all["preview"].offsetHeight; if(obImg.width > iContentWidth || obImg.height > iContentHeight) { if(obImg.width <= iContentWidth) { document.all["pv"].height = iContentHeight; document.all["pv"].width = Math.round(iContentHeight * obImg.width / obImg.height); } else if(obImg.height <= iContentHeight) { document.all["pv"].width = iContentWidth; document.all["pv"].height = Math.round(iContentWidth * obImg.height / obImg.width); } else { if(obImg.width / iContentWidth > obImg.height / iContentHeight) { document.all["pv"].width = iContentWidth; document.all["pv"].height = Math.round(iContentWidth * obImg.height / obImg.width); } else { document.all["pv"].height = iContentHeight; document.all["pv"].width = Math.round(iContentHeight * obImg.width / obImg.height); } } } else { document.all["pv"].width = obImg.width; document.all["pv"].height = obImg.height; } document.all["pv"].src = obImg.src; document.all["pv"].style.display = "block"; } function OnClickUpload() { bOK = false; var sFile = document.fmUpload.upfile.value; if(/(\.[^\\\/\.]*)$/ig.exec(sFile) == null) { ShowInfo("图片大小:? KB 图片尺寸:? x ?"); document.all["pv"].style.display = "none"; alert("不能识别的文件扩展名!"); return; } if(validExt.indexOf(RegExp.$1 + "|") == -1) { ShowInfo("图片大小:? KB 图片尺寸:? x ?"); document.all["pv"].style.display = "none"; alert("不能上传 " + RegExp.$1 + " 格式的文件"); return; } obImg.src = sFile; setTimeout("CheckProperty()",0); } function OnSubmitForm() { alert("test"); return false; } function Upload_Err() { ShowInfo("上传文件失败!"); } </script> <table align="center" width="50%" height="50%" border="1" cellspacing="0"> <form name="fmUpload" action="upload-do.php" method="post" enctype="multipart/form-data" onSubmit="return OnSubmitForm()" target="frmDoUpload"> <tr> <td width="100%"><input type="file" name="upfile" id="upfile" onChange="OnClickUpload()"></td> <td> <input type="submit" name="bnSubmit" value="上传"> <input type="hidden" name="fileExt"> <input type="hidden" name="picType"> <input type="hidden" name="isAutoSmall"> </td> </tr> <tr><td align="center" id="info" colspan="2"> </td></tr> <tr> <td height="100%" colspan="2" align="center" valign="middle"> <div id="preview"><img id="pv"></div> </td> </tr> <tr style="display:none"> <td colspan="2" height=50></td> </tr> </form> </table> </BODY> </HTML>
提示:您可以先修改部分代码再运行
站内搜索
:
标题
内容
下一篇
使用js/javascript制作特殊的字符效果
上一篇
无法拦截与屏蔽的网页漂浮图片广告代码 完全自定义 全屏飘动
本栏目最新
栏目最新列表
使用JS对select动态添加options操作 [IE&Fi
符合标准的对联广告代码
使用js/javascript制作特殊的字符效果
图片上传预览,可显示文件大小,宽、高
文件上传前台控制检测预览程序 v0.6
网站优化策划
栏目最新列表
增加网站外链的快速方法
网站上线前必做的30个检查
新的友情链接参考标准(没有google的PR情况
优化Google的AdSense广告的五个工具
王通讲SEO八大基础
站点最新
站点最新列表
微博推广的一些技巧
xhEditor v1.1.7 发布,
收集的一些轻量级非常实
50个新鲜兼容最新版本的
javascript中cookie的设
Excel中出现#VALUE!、#D
jquery插件:飞飞表情插件
十个使用HTML5开发的精彩
支持HTML5的浏览器有哪些
飞妮莫属:漫画:如何写出
历史最热10条信息
MIME介绍 及
[
1
] [
2
] [
3
]
巧用Google和迅雷来下载
Transact SQL 常
[
1
] [
2
]
VIA Rhine II Fast Ethe
电脑常用端
[
1
] [
2
] [
3
]
Do you get a kick out
十道羊皮卷 欣赏+mp3版+
每日一句:A friend and
每日一句:Theres no tu
经典__悟透JavaScript
相关专题
相关专题列表
图片上传预览,可显示文
文件上传前台控制检测预
图片上传前预览缩略图
伟哥博客
西安房产
123最新电影
三四六四
关于站点
|
免责声明
|
联系站长
|
网站地图
|
陕ICP备07002804号
WEB技术QQ交流群:72840059
©2007 ffasp.com. 版权所有