1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Essai Upload</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<style type="text/css">
#loading {display:none;}
#supp_image {display:none;}
.error {color:#FF0000;font-weight:bold;}
.success, .success a {color:#009900;font-weight:bold;}
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery_ajax_upload.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var upload = new AjaxUpload('#userfile', {
action: 'upload_essai.php', //upload script
onSubmit : function(file, extension)
{
$("#loading").show(); // Montre l'animation de telechargement
if (! (extension && /^(jpg|png|jpeg|gif|pdf)$/.test(extension))) // Verifie les extensions de fichier
{
$("#loading").hide();
$("<span class='error'>Erreur : Format de fichier non valide ! <br /> Formats autorisés : jpg, png, jpeg, gif, pdf </span>").appendTo("#file_holder #errormes");
return false;
}
else // masque l'erreur si l'extension est OK
{ $('.error').hide(); }
upload.setData({'file': file}); // Envoi du fichier
},
onComplete : function(file, response)
{
$("#loading").hide(); // Masque l'animation de telechargement
$(".success").css("display", "block"); // Montre le message du succes
$(".image_fichier").css("display", "block"); // Montre l'image !
$(".nom_fichier_upload").css("display", "block"); // Montre le nom recupere du fichier !
var oBody = $(".iframe").contents().find("div"); // affecte le message d'erreur
$(oBody).appendTo("#file_holder #errormes");
}
});
});
</script>
<script>
$(document).ready(function() {
action: 'supp_essai.php'
});
</script>
</head>
<body>
<div id="file_holder">
<form action="" method="post" enctype="multipart/form-data">
<h3>Essai d'upload avec ajax ! </h3>
<p>
<label for="userfile">Votre image : </label>
<input id="userfile" class="input" type="file" name="userfile" />
</p>
<div id="loading"><img src="loader.gif" alt="Téléchargement" /> Téléchargement en cours, patientez...</div>
<div id="errormes"></div>
</form>
</div>
</body>
</html> |
Partager