多个图像上传和预览 [英] multiple image upload and preview

查看:116
本文介绍了多个图像上传和预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何上传多张图片并展示他们的预览...

I am learning how to upload multiple images and showing their preview...

我遇到了以下代码

<html>
<head>
<style>
.input-file-row-1:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}

.input-file-row-1{
display: inline-block;
margin-top: 25px;
position: relative;
}

#preview_image {
display: none;
width: 90px;
height: 90px;
margin: 2px 0px 0px 5px;
border-radius: 10px;
}

.upload-file-container { 
position: relative; 
width: 100px; 
height: 137px; 
overflow: hidden;   
background: url('images/picplus.png') top center no-repeat;
float: left;
margin-left: 23px;
} 

.upload-file-container-text{
font-family: Arial, sans-serif;
font-size: 12px;
color: #719d2b;
line-height: 17px;
text-align: center;
display: block;
position: absolute; 
left: 0; 
bottom: 0; 
width: 100px; 
height: 35px;
}

.upload-file-container-text > span{
border-bottom: 1px solid #719d2b;
cursor: pointer;
}

.one_opacity_0 {
opacity: 0;
height: 0;
width: 1px;
float: left;
}
</style>
<script>
function readURL(input,target)
{
if(input.files && input.files[0])
{
var reader=new FileReader();
var image_target=$(target);
reader.onload=function(e)
{
    image_target.attr('src',e.target.result).show();
};
reader.readAsDataUrl(input.files[0]);
}
}

$("patient_pic").live("change",function(){
readURL(this,"#preview_image")
});
</script>

</head>

<body>
<form name="" method="post" action="#" class="feedback-form-1">
<fieldset>
    <div class="input-file-row-1">
        <div class="upload-file-container">
            <img id="preview_image" src="#" alt="" />
            <div class="upload-file-container-text">
                <div class = 'one_opacity_0'>
                    <input type="file" id="patient_pic" label = "add" />
                </div>
                <span> Add Photo </span>
            </div>

<div class="upload-file-container-text">
                <div class = 'one_opacity_0'>
                    <input type="file" id="patient_pic" label = "add" />
                </div>
                <span> Add Photo </span>
            </div>

</div>
    </div>
</fieldset>
</form>
</body>

</html>

我遇到过这个 http://jsfiddle.net/dn9Sr/2/ (小提琴),这完全解释了我。
但作为初学者我知道它包含一个jquery库,它清楚地显示了Fiddle的框架扩展。
现在我的问题是。当我在我的机器上开始编码时,我究竟应该如何包含它。

I came across this http://jsfiddle.net/dn9Sr/2/ (fiddle) which explains it perfectly to me. But being a beginner I know it includes a jquery library which clearly shows in framework extension of Fiddle. now my issue is. How exactly should I include it when I start the coding on my machine.

将包含在head()部分中以调用库...
谢谢

what will be included in the head() section to make a call to the library... thank you

推荐答案

我有一个预览多个图片上传的解决方案
https://maraustria.wordpress.com/ 2014/04/25 /多重选择和预览图像文件上传/

I have a solution to preview multiple image upload https://maraustria.wordpress.com/2014/04/25/multiple-select-and-preview-of-image-of-file-upload/

Html

<form id="post-form" class="post-form" method="post">
<label for="files">Select multiple files: </label>
<input id="files" type="file" multiple/>
<output id="result" />
</form>

Javascript

Javascript

window.onload = function(){
    //Check File API support
    if(window.File && window.FileList && window.FileReader)
    {
        var filesInput = document.getElementById("files");
        filesInput.addEventListener("change", function(event){
            var files = event.target.files; //FileList object
            var output = document.getElementById("result");
            for(var i = 0; i< files.length; i++)
            {
                var file = files[i];
                //Only pics
                if(!file.type.match(‘image’))
                    continue;
                var picReader = new FileReader();
                picReader.addEventListener("load",function(event){
                    var picFile = event.target;
                    var div = document.createElement("div");
                    div.innerHTML = "<img class=’thumbnail’ src=’" + picFile.result + "‘" +
                    "title=’" + picFile.name + "‘/>";
                    output.insertBefore(div,null);
                });
                //Read the image
                picReader.readAsDataURL(file);
            }
        });
    }
    else
    {
        console.log("Your browser does not support File API");
    }
}

Css

body{
font-family: ‘Segoe UI’;
font-size: 12pt;
}

header h1{
font-size:12pt;
color: #fff;
background-color: #1BA1E2;
padding: 20px;

}
article
{
width: 80%;
margin:auto;
margin-top:10px;
}

.thumbnail{

height: 100px;
margin: 10px;
}

http://jsfiddle.net/0GiS0/Yvgc2/

这篇关于多个图像上传和预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆