I'd like to use my file-upload script in a modal/dialog which is created after the document is loaded.
Also i use the alertify library to have a better dialog box.
Here is my code :
1 - My alertify script (profile.js) which create the form :
$("#profil").click(function () {
alertify.minimalDialog || alertify.dialog('minimalDialog', function () {
return {
main: function (content) {
this.setContent(content);
this.set('resizable',true).resizeTo('80%','50%');
this.set('title',"Changer votre photo de profil");
}
};
});
alertify.minimalDialog('<form id="formupload" method="POST"><p><img id="imagepreview" class="id_img" width="auto" height="60px" src="../../images/profils/min/3266.jpg"></p> <p class="label-w100"><input id="fileupload" type="file" name="files[]" accept="image/gif, image/jpg, image/jpeg, image/png"/><div id="progress"><div class="bar" style="width: 0%;"></div></div></p><p id="chargementimage"></p><div class="grand-trait"></div><p class="center"><input id="submit" type="submit" value="Envoyer" class="envoyer"/></p></form>');
})
2 - My script which would allow to load the image in a temporary folder
$(document).on("change", "#fileupload", function(){
var url = window.location.hostname + "/json/ec-informations/upload_img2.php";
alert(url);
$('#fileupload').fileupload({
dataType: 'json',
url: url,
maxChunkSize: 1000000,
maxFileSize: 5000000,
formData: {'csrf': 'csrf'},
done: function (e, data) {
fichier = "";
$.each(data.result.files, function (index, file) {
$('#progress').after(file.name).appendTo(document.body);
fichier = file.name;
$("input[name=img_tmp]").val(fichier);
$('#progress').appendTo('#chargementimage');
$('#chargementimage').after('Image correctement chargée, finalisez votre proposition en appuyant sur Envoyer.');
$('#imagepreview').attr('src', '' + fichier);
if (file.error) {
alert(file.error);
location.reload();
}
});
if (data.erreur == 'Filetype not allowed') {
alert('Le format de fichier est mauvais');
}
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .bar').css(
'width',
progress + '%'
);
}
});
});
My problem is that when I select the image, i dont succeed to bring informations inside my upload_img2.php.
Usually, i have no problem with uploadfile because my form is created before, but not here.
I hope i've been clear, thanks you for your help !