Professional Documents
Culture Documents
Projet
Projet
Projet
<div id="start">
</div>
<div id="messages"></div>
<span>0</span>%
</progress>
</div>
</label>
</form>
// Imports
//
@import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css);
@import url('https://fonts.googleapis.com/css?family=Roboto');
// Vars and Reset
//
$theme: #454cad;
$dark-text: #5f6982;
h2 {
font-size: 26px;
line-height: 1;
color: $theme;
margin-bottom: 0;
p{
font-size: 18px;
color: $dark-text;
// Upload Demo
//
.uploader {
display: block;
clear: both;
margin: 0 auto;
width: 100%;
max-width: 600px;
label {
float: left;
clear: both;
width: 100%;
text-align: center;
background: #fff;
border-radius: 7px;
user-select: none;
&:hover {
border-color: $theme;
&.hover {
#start {
i.fa {
transform: scale(0.8);
opacity: 0.3;
#start {
float: left;
clear: both;
width: 100%;
&.hidden {
display: none;
i.fa {
font-size: 50px;
margin-bottom: 1rem;
#response {
float: left;
clear: both;
width: 100%;
&.hidden {
display: none;
#messages {
margin-bottom: .5rem;
#file-image {
display: inline;
width: auto;
height: auto;
max-width: 180px;
&.hidden {
display: none;
}
#notimage {
display: block;
float: left;
clear: both;
width: 100%;
&.hidden {
display: none;
progress,
.progress {
// appearance: none;
display: inline;
clear: both;
margin: 0 auto;
width: 100%;
max-width: 180px;
height: 8px;
border: 0;
border-radius: 4px;
background-color: #eee;
overflow: hidden;
.progress[value]::-webkit-progress-bar {
border-radius: 4px;
background-color: #eee;
}
.progress[value]::-webkit-progress-value {
border-radius: 4px;
.progress[value]::-moz-progress-bar {
border-radius: 4px;
input[type="file"] {
display: none;
div {
margin: 0 0 .5rem 0;
color: $dark-text;
.btn {
display: inline-block;
clear: both;
font-family: inherit;
font-weight: 700;
font-size: 14px;
text-decoration: none;
text-transform: initial;
border: none;
border-radius: .2rem;
outline: none;
padding: 0 1rem;
height: 36px;
line-height: 36px;
color: #fff;
box-sizing: border-box;
background: $theme;
border-color: $theme;
cursor: pointer;
// File Upload
//
function ekUpload(){
function Init() {
console.log("Upload Initialised");
fileDrag = document.getElementById('file-drag'),
submitButton = document.getElementById('submit-button');
// Is XHR2 available?
if (xhr.upload) {
// File Drop
function fileDragHover(e) {
e.stopPropagation();
e.preventDefault();
function fileSelectHandler(e) {
fileDragHover(e);
parseFile(f);
uploadFile(f);
// Output
function output(msg) {
// Response
var m = document.getElementById('messages');
m.innerHTML = msg;
}
function parseFile(file) {
console.log(file.name);
output(
);
// console.log(fileType);
if (isGood) {
document.getElementById('start').classList.add("hidden");
document.getElementById('response').classList.remove("hidden");
document.getElementById('notimage').classList.add("hidden");
// Thumbnail Preview
document.getElementById('file-image').classList.remove("hidden");
document.getElementById('file-image').src = URL.createObjectURL(file);
else {
document.getElementById('file-image').classList.add("hidden");
document.getElementById('notimage').classList.remove("hidden");
document.getElementById('start').classList.remove("hidden");
document.getElementById('response').classList.add("hidden");
document.getElementById("file-upload-form").reset();
}
function setProgressMaxValue(e) {
if (e.lengthComputable) {
pBar.max = e.total;
function updateFileProgress(e) {
if (e.lengthComputable) {
pBar.value = e.loaded;
function uploadFile(file) {
fileInput = document.getElementById('class-roster-file'),
pBar = document.getElementById('file-progress'),
fileSizeLimit = 1024; // In MB
if (xhr.upload) {
// Progress bar
pBar.style.display = 'inline';
if (xhr.readyState == 4) {
// Everything is good!
// document.location.reload(true);
};
// Start upload
xhr.setRequestHeader('X-File-Name', file.name);
xhr.setRequestHeader('X-File-Size', file.size);
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
xhr.send(file);
} else {
Init();
} else {
document.getElementById('file-drag').style.display = 'none';
ekUpload();
<html>
<head>
<script type='text/javascript'>
function preview_image(event)
{
var reader = new FileReader();
reader.onload = function()
{
var output = document.getElementById('output_image');
output.src = reader.result;
}
reader.readAsDataURL(event.target.files[0]);
}
</script>
<style>
body
{
width:100%;
margin:0 auto;
padding:0px;
font-family:helvetica;
background-color:#0B3861;
}
#wrapper
{
text-align:center;
margin:0 auto;
padding:0px;
width:995px;
}
#output_image
{
max-width:300px;
}
</style>
</head>
<body>
<div id="wrapper">
<input type="file" accept="image/*"
onchange="preview_image(event)">
<img id="output_image"/>
</div>
</body>
</html>