Home > php教程 > PHP开发 > Input file upload image preview function example code

Input file upload image preview function example code

高洛峰
Release: 2016-12-09 09:55:19
Original
1343 people have browsed it

Input file upload image preview is actually very simple, but it feels amazing if you have never done it before. Today I will take off its mysterious veil. In fact, the principle is really simple. Everyone can understand it through a piece of code below.

The specific code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="jquery.js"></script>
</head>
<body>
<input type="file" multiple id="inputs"/> //multiple(多文件上传)
<div id=&#39;dd&#39;></div>
<script>
$(document).ready(function () {
$("#inputs").change(function () {
var fil = this.files;
for (var i = 0; i < fil.length; i++) {
reads(fil[i]);
}
});
});
function reads(fil){
var reader = new FileReader();
reader.readAsDataURL(fil);
reader.onload = function()
{
document.getElementById("dd").innerHTML += "<img src=&#39;"+reader.result+"&#39;>";
};
}
</script>
</body>
<html>
Copy after login

Achieve direct preview of uploaded images, avoiding the redundant process of reading images after submission

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template