文件上传:input file FileReader
js:
window.onload = function () {
var input = document.getElementById('input-file'),
info = document.getElementById('info'),
preview = document.getElementById('preview');
input.addEventListener('change',function () {
preview.style.backgroundImage = '';
if(!input.value){
info.innerText = '没有选择文件';
return false;
}
var file = input.files[0];
info.innerText = '文件名:' + file.name + '<br>'
+ '文件大小:' + file.size + '<br>'
+ '最后修改时间:' + file.lastModifiedDate;
if(file.type != 'image/png' && file.type != 'image/jpeg' && file.type != 'image/gif'){
var p = document.createElement('p');
p.innerText = '不是有效的图片文件格式,请重试!';
info.appendChild(p);
return false;
}
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
var data = e.target.result;
preview.style.backgroundImage = 'url('+data+')';
}
})
}
html:
<div class="testInput">
<p><input type="file" id="input-file" /></p>
<p id="info"></p>
<p id="preview" style="width: 400px; height: 500px;"></p>
</div>
文件上传:input file FileReader的更多相关文章
- 改变文件上传input file类型的外观
当我们使用文件上传功能时,<input type="file">,但是外观有点不符合口味,如何解决这个问题? <input type="file&quo ...
- 基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用
Bootstrap文件上传插件File Input是一个不错的文件上传控件,但是搜索使用到的案例不多,使用的时候,也是一步一个脚印一样摸着石头过河,这个控件在界面呈现上,叫我之前使用过的Uploadi ...
- Bootstrap文件上传插件File Input的使用
基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用 Bootstrap文件上传插件File Input是一个不错的文件上传控件, ...
- (转)基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用
http://www.cnblogs.com/wuhuacong/p/4774396.html Bootstrap文件上传插件File Input是一个不错的文件上传控件,但是搜索使用到的案例不多,使 ...
- 多文件上传 input 的multiple 属性
一.上传多张图片并且预览 HTML: <div class="container"> <label>请选择一个图像文件:</label> < ...
- Spring MVC-表单(Form)标签-文件上传(File Upload)示例(转载实践)
以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_upload.htm 说明:示例基于Spring MVC 4.1.6. 以下示例显 ...
- DVWA 黑客攻防演练(五)文件上传漏洞 File Upload
说起文件上传漏洞 ,可谓是印象深刻.有次公司的网站突然访问不到了,同事去服务器看了一下.所有 webroot 文件夹下的所有文件都被重命名成其他文件,比如 jsp 文件变成 jsp.s ,以致于路径映 ...
- AFNetworking 文件上传Data,File图片,文件等上传
一:AFNetworking的文件上传: 主要几个以下类似 - (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name e ...
- vuetify | vue | 文件上传组件 | file | upload | form input[type="file"]
今天无聊地写vuecli3听歌的时候,遇到了上传文件到Django的自我需求,然后就到vuetify的表单组件里找upload btn,发现居然没有!!! 顿时惊了个呆,要知道之前用element做操 ...
- 文件上传input type="file"样式美化
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
随机推荐
- 查看nvidia显卡命令
http://blog.csdn.net/luo123n/article/details/50296973 nvidia-smi
- ImportError: No module named 'serial'
/******************************************************************************** * ImportError: No ...
- 高性能Mysql学习笔记之事务
传送门 什么是事务? 事务就是一组原子性的SQL查询,或者说一个独立的工作单元.如果数据库引擎能够成功地对数据库应用该组查询的全部语句,那么就会执行该组查询.如果其中有任何一条语句因为崩溃或其他原因无 ...
- maven安装之后,或者升级之后遇到的问题:could not find or load main class org.codehaus.plexus.class.....
从maven2升级到maven3或者从maven3降级到maven2,M2_HOME环境变量改变后,在终端执行mvn -v,出现如下错误: Exception in thread "main ...
- 20165212 2017-2018-2《Java程序设计》课程总结
20165212 2017-2018-2<Java程序设计>课程总结 作业链接汇总 每周作业链接 预备作业1:我期望的师生关系 预备作业2:做中学learning by doing个人感想 ...
- 使用_beginThreadex创建多线程(C语言版多线程)
_beginThreadex创建多线程解读 一.需要的头文件支持 #include <process.h> // for _beginthread() 需要的设置:Proj ...
- linux pwd命令查看当前路径命令
命令简介: 该命令用来显示目前所在的工作目录.指令英文原义:print work directory执行权限 :All User指令所在路径:/usr/bin/pwd 或 /bin/pwd 命令语法: ...
- open_input_file函数调用结构图(转)
open_input_file函数调用结构图(有些重复的函数调用就略掉了,大致是按流程往下的). 函数大致说明: AVFormatContext *avformat_alloc_context(voi ...
- Zabbix 报警通知邮件和微信vim /etc/hosts
1安装 sendmail # yum -y install sendmail echo 'This is test mail'>body.txt mail -s 'Test mail' 3013 ...
- Tomcat 7 的七大新特性(更容易将Tomcat内嵌到应用去中去 )
Tomcat的7引入了许多新功能,并对现有功能进行了增强.很多文章列出了Tomcat 7的新功能,但大多数并没有详细解释它们,或指出它们的不足,或提供代码示例.本文将明确描述TOMCAT 7中七个最显 ...