html5 & upload files
html5 & upload files
https://www.sitepoint.com/html5-ajax-file-upload/
https://www.webcodegeeks.com/html5/html5-file-upload-example
<input type="file" id="fileinput" />
document.getElementById('fileinput').addEventListener('change', function(){
var file = this.files[0];
// This code is only for demo ...
console.log("name : " + file.name);
console.log("size : " + file.size);
console.log("type : " + file.type);
console.log("date : " + file.lastModified);
}, false);
multi files
<input type="file" id="fileinput" multiple="multiple" />
document.getElementById('fileinput').addEventListener('change', function(){
for(var i = 0; i<this.files.length; i++){
var file = this.files[i];
// This code is only for demo ...
console.group("File "+i);
console.log("name : " + file.name);
console.log("size : " + file.size);
console.log("type : " + file.type);
console.log("date : " + file.lastModified);
console.groupEnd();
}
}, false);
image
<input type="file" id="fileinput" multiple="multiple" accept="image/*" />
// Previewing Files
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Preview images</title>
<style>
#gallery .thumbnail{
width:150px;
height: 150px;
float:left;
margin:2px;
}
#gallery .thumbnail img{
width:150px;
height: 150px;
}
</style>
</head>
<body>
<h2>Upload images ...</h2>
<input type="file" id="fileinput" multiple="multiple" accept="image/*" />
<div id="gallery"></div>
<script src="gallery.js"></script>
</body>
</html>
var uploadfiles = document.querySelector('#fileinput');
uploadfiles.addEventListener('change', function () {
var files = this.files;
for(var i=0; i<files.length; i++){
previewImage(this.files[i]);
}
}, false);
function previewImage(file) {
var galleryId = "gallery";
var gallery = document.getElementById(galleryId);
var imageType = /image.*/;
if (!file.type.match(imageType)) {
throw "File Type must be an image";
}
var thumb = document.createElement("div");
thumb.classList.add('thumbnail'); // Add the class thumbnail to the created div
var img = document.createElement("img");
img.file = file;
thumb.appendChild(img);
gallery.appendChild(thumb);
// Using FileReader to display the image content
var reader = new FileReader();
reader.onload = (function(aImg) { return function(e) { aImg.src = e.target.result; }; })(img);
reader.readAsDataURL(file);
}
function uploadFile(file){
var url = 'server/index.php';
var xhr = new XMLHttpRequest();
var fd = new FormData();
xhr.open("POST", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
// Every thing ok, file uploaded
console.log(xhr.responseText); // handle response.
}
};
fd.append("upload_file", file);
xhr.send(fd);
}
var uploadfiles = document.querySelector('#uploadfiles');
uploadfiles.addEventListener('change', function () {
var files = this.files;
for(var i=0; i<files.length; i++){
uploadFile(this.files[i]); // call the function to upload the file
}
}, false);
FileAPI
https://w3c.github.io/FileAPI/
https://developer.mozilla.org/en-US/docs/Web/API/File
html5 & upload files的更多相关文章
- Upload Files To FTP in Oracle Forms D2k
Upload Files To FTP in Oracle Forms D2k Use following procedure to upload files to Ftp. PROCEDURE ...
- How To Use XDOLoader to Manage, Download and Upload Files? (文档 ID 469585.1)
Applies to: BI Publisher (formerly XML Publisher) - Version 5.6.3 to 5.6.3 [Release 5] Information ...
- How To Use XDOLoader to Manage, Download and Upload Files? (DOC ID 469585.1)
In this Document Goal Fix Downloading Files Uploading Files References Applies to: BI Publishe ...
- HTTPWebrequest上传文件--Upload files with HTTPWebrequest (multipart/form-data)
使用HTTPWebrequest上传文件遇到问题,可以参考Upload files with HTTPWebrequest (multipart/form-data)来解决 https://stack ...
- Upload Files In ASP.NET Core 1.0 (Form POST And JQuery Ajax)
Uploading files is a common requirement in web applications. In ASP.NET Core 1.0 uploading files and ...
- AzCopy Upload Files
We can use many ways upload our Files to Azure, Than I Introduction to you a good way, AzCopy ! 1. ...
- Upload files to aliyunOSS with bootstrap-fileinput
本文主要涉及两个概念: 阿里云OSS:对象存储(Object Storage Service,简称OSS),是阿里云对外提供的海量.安全和高可靠的云存储服务. bootstrap-fileinput: ...
- SharePoint自动化系列——Upload files to SharePoint library using PowerShell.
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 日常的SharePoint站点测试中,我们经常要做各种各样的数据,今天又写了几个脚本,发现自己写的 ...
- [Express] Upload Files with Express
In this lesson we create a new Express web server app for handling file uploads and persisting them ...
随机推荐
- Kubernetes1.91(K8s)安装部署过程(四)--Master节点安装
再次明确下架构: 三台虚拟机 centos 7.4系统,docker为17版本,ip为10.10.90.105到107,其中105位master,接下来的master相关组件安装到此机器上. etc ...
- Ubuntu18.04安装Teamviewer
首先,打开TeamViewer的下载页面,下载Debian/Ubuntu的Deb安装包. 这里有64位和32位安装包选项.可以在Terminal(终端)中输入uname -a 查看自己系统版本是64位 ...
- OpenCV——创建Mat对象、格式化输出、常用数据结构和函数(point,vector、Scalar、Size、Rect、cvtColor)
创建Mat对象:
- Python2.7-fileinput
fileinput 模块,对输入的文件流进行迭代操作,可以说是对 open() 的一个扩展,它可以直接修改文件,也可以对他们进行备份 模块方法: fileinput.input([files[, in ...
- 七,ESP8266-UDP(基于Lua脚本语言)
https://www.cnblogs.com/yangfengwu/p/7533302.html 那天朋友问我为什么有UDP Sever 和 UDP Client ,,我说:每个人想的不一样,设 ...
- python基础学习1-变量定义赋值,屏幕输入输出
一.变量定义赋值 输入输出屏幕显示 : name = input("input is your name") age =int( input("input is your ...
- Macaca之Android原理浅析
经过研究macaca的android模块源码,原理主要由以下三块构成 一.uiautomator TODO 二.nanohttp TODO 二.adb forward TODO
- 用Spring.Services整合 thrift0.9.2生成的wcf中间代码-复杂的架构带来简单的代码和高可维护性
最近一直在看关于thrift的相关文章,涉及到的内容的基本都是表层的.一旦具体要用到实际的项目中的时候就会遇到各种问题了! 比如说:thrift 的服务器端载体的选择.中间代码的生成options(a ...
- javascript source map 的使用
之前发现VS.NET会为压缩的js文添加一个与文件名同名的.map文件,一直没有搞懂他是用来做什么的,直接删除掉运行时浏览器又会报错,后来google了一直才真正搞懂了这个小小的map文件背后的巨大意 ...
- svn插件下载的两种方式
1.下载SVN插件 SVN插件下载地址及更新地址,你根据需要选择你需要的版本.现在最新是1.8.x Links for 1.8.x Release: Eclipse up ...