ドキュメントがロードされた後に作成されるモーダル/ダイアログで、ファイル アップロード スクリプトを使用したいと思います。
また、alertify ライブラリを使用して、ダイアログ ボックスを改善しています。
これが私のコードです:
1 - フォームを作成するアラートスクリプト (profile.js):
$("#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 - 一時フォルダーに画像をロードできるスクリプト
$(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 + '%'
);
}
});
});
私の問題は、画像を選択したときに、upload_img2.php 内に情報を取り込むことができないことです。
通常、フォームは以前に作成されていますが、ここでは作成されていないため、uploadfile に問題はありません。
私は明確だったと思います、あなたの助けに感謝します!