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的更多相关文章

  1. 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 ...

  2. 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  ...

  3. 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 ...

  4. HTTPWebrequest上传文件--Upload files with HTTPWebrequest (multipart/form-data)

    使用HTTPWebrequest上传文件遇到问题,可以参考Upload files with HTTPWebrequest (multipart/form-data)来解决 https://stack ...

  5. 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 ...

  6. AzCopy Upload Files

    We can use many ways upload our Files to Azure, Than I  Introduction to you a good way, AzCopy ! 1. ...

  7. Upload files to aliyunOSS with bootstrap-fileinput

    本文主要涉及两个概念: 阿里云OSS:对象存储(Object Storage Service,简称OSS),是阿里云对外提供的海量.安全和高可靠的云存储服务. bootstrap-fileinput: ...

  8. SharePoint自动化系列——Upload files to SharePoint library using PowerShell.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 日常的SharePoint站点测试中,我们经常要做各种各样的数据,今天又写了几个脚本,发现自己写的 ...

  9. [Express] Upload Files with Express

    In this lesson we create a new Express web server app for handling file uploads and persisting them ...

随机推荐

  1. jqgrid 主键列的设定

    1.如果需要对jqgrid表格数据有互动操作,需要设定主键列. 2.主键列的作用为:在进行jqgrid表格数据交互(编辑.新增.删除行)时,是通过主键列的值来作为引导值来的. 3.注意:不要给一个jq ...

  2. 微信小程序开发 [04] 模板和模块化

    1.模板 如果相同的wxml代码可能在不同的页面重复使用,ctrl+c配合ctrl+v的方式,后期维护起来未免也太麻烦了.微信提供了"模板",可以在模板中定义代码片段,然后在不同的 ...

  3. Segment Tree Beats 区间最值问题

    Segment Tree Beats 区间最值问题 线段树一类特殊技巧! 引出:CF671C Ultimate Weirdness of an Array 其实是考试题,改题的时候并不会区间取最值,区 ...

  4. 大数据入门第二十一天——scala入门(二)并发编程Akka

    一.概述 1.什么是akka Akka基于Actor模型,提供了一个用于构建可扩展的(Scalable).弹性的(Resilient).快速响应的(Responsive)应用程序的平台. 更多入门的基 ...

  5. [2016北京集训试题15]cot-[分块]

    Description Solution 如图,假如我们知道了以任何一个点为顶点的135-180度的前缀和和90-180度的前缀和,我们就可以搞出三角形的面积. 差分.add[i][j]和dev[i] ...

  6. C语言如何向系统接要存

    C语言如何向系统接要存,就有这么三种方式: 1.向栈要. 2.向堆要. 3.向数据段要. 这一下就扯出了三种内存空间,内存空间的本质是一样的,一个地址对应一个方框,方框里可以放数据.但是为了更好的去 ...

  7. 【转载】VS配置路径和宏

    原文路径:http://blog.csdn.net/puttytree/article/details/7838419 在介绍项目配置之前,先说明两点 1. 项目配置中,最好不要使用相对路径,更不要使 ...

  8. Number.toString SyntaxError

    问题分析 问题 20.toString(); VM163:1 Uncaught SyntaxError: Invalid or unexpected token 分析 "."号的原 ...

  9. R绘图 第九篇:绘制散点图和气泡图(ggplot2)

    绘制散点图(scatterplots)使用geom_point()函数,气泡图(bubblechart)也是一个散点图,只不过点的大小由一个变量(size)来控制.散点图潜在的最大问题是过度绘图:当一 ...

  10. JVM技术周报第2期

    JVM技术周报第2期 JVM技术周报分享JVM技术交流群的讨论内容,由群内成员整理归纳而成.如果你有兴趣入群讨论,请关注「Java技术精选」公众号,通过右下角菜单「入群交流」加我好友,获取入群详情. ...