限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

jquery支持AJAX多文件上传接口php源码

所属分类: 网页特效-图片特效&上传    2023-10-29 08:21:59

jquery支持AJAX多文件上传接口php源码 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery支持AJAX多文件上传接口php源码(共20个文件)

    • index.html

使用方法

  • code
  • source
  1. infoPhp = [];
  2. postfiles = [];
  3. formData = new FormData();
  4. $(function() {
  5. $.fn.swallow = function (options){
  6. //Config path by default
  7. var pat = $.extend({
  8. imgPath : "img/",
  9. phpPath : "php/",
  10. targetPath : "nest/"
  11. }, options);
  12. //Search on the PHP server configuration items
  13. $.ajax({url:pat.phpPath + 'info.php',async:false,
  14. success: (s) => {infoPhp.push(JSON.parse(s));},
  15. error: () => {alert('require ==> info.php');return false;},
  16. })
  17. //Config options user
  18. var ext = $.extend({
  19. swallowTag : false,
  20. targetTag : infoPhp[0]['tag_swallow'],
  21. method : "POST",
  22. enctype : "multipart/form-data",
  23. acceptFiles : "*",
  24. maxFileSize : infoPhp[0]['upload_max_filesize'],
  25. maxFileCount : infoPhp[0]['max_file_uploads'],
  26. postMaxSize : infoPhp[0]['post_max_size'],
  27. maxImgQuality : 100,
  28. defaultImg : "file.png",
  29. labelInput1 : "Add your files",
  30. labelInput2 : "Number of files",
  31. labelName : "Name",
  32. labelType : "Type file",
  33. labelModified : "Modified",
  34. labelSize : "Size",
  35. labelSaveBtn : "Save",
  36. labelDeleteBtn : "Delete",
  37. labelLoadingBtn : "Loading...",
  38. labelSuccess : "File upload successful",
  39. labelAcceptFiles : "Accepted formats",
  40. labelMaxFileSize : "Max size accept",
  41. labelMaxFileCount : "Max files accept",
  42. labelAllDenied : "Denied !",
  43. onSuccess : function (response, statut) {},
  44. onError : function (response, statut, erreur) {}
  45. }, options);
  46. //Form input bootstrap 4
  47. $(this).append('\
  48. <div class="row">\
  49. <div class="col-12 mb-2">\
  50. <form method="post" enctype="'+ ext.enctype +'">\
  51. <div class="alert alert-danger d-none fade show" role="alert" id="ErrUpload"></div>\
  52. <div class="custom-file">\
  53. <input type="file" class="custom-file-input" id="swallow" name="swallow[]" multiple>\
  54. <label class="custom-file-label" for="swallow">'+ ext.labelInput1 +'</label>\
  55. </div>\
  56. <div class="mt-1">\
  57. <button class="btn btn-block btn-success d-none" id="SaveFiles" type="button">'+ ext.labelSaveBtn +'</button>\
  58. <button class="btn btn-block btn-info WaitSpinner d-none" disabled><span class="spinner-grow spinner-grow-sm"></span> '+ ext.labelLoadingBtn +'</button>\
  59. </div>\
  60. </form>\
  61. </div>\
  62. <div class="col-12 mt-2">\
  63. <ul class="list-unstyled gallery"></ul>\
  64. <div class="toast d-none" aria-atomic="true" data-delay="2000" id="SuccUpload">\
  65. <div class="toast-header">\
  66. <img src="'+ pat.imgPath + ext.defaultImg +'" class="rounded mr-2" height="15" width="15">\
  67. <strong class="mr-auto">Swallow</strong>\
  68. <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">\
  69. <span aria-hidden="true">&times;</span>\
  70. </button>\
  71. </div>\
  72. <div class="toast-body">'+ ext.labelSuccess +'</div>\
  73. </div>\
  74. </div>\
  75. </div>\
  76. ')
  77. //Tag file or multiple files
  78. $("#swallow").on("change", function(e) {
  79. const files = e.currentTarget.files;
  80. $("#ErrUpload").empty().removeClass('d-block').addClass('d-none');
  81. $("#SaveFiles").removeClass('d-block').addClass('d-none');
  82. //Defaut save formData
  83. $.each($(this)[0].files, function(i, file) {formData.append('swallow[]', file);});
  84. Object.keys(files).forEach(i => {
  85. const file = files[i];
  86. //Option type files
  87. if(ext.acceptFiles != "*"){
  88. afAccept = false;
  89. afArray = ext.acceptFiles.split(',');
  90. afArray.forEach(element => {if(file.type === element){afAccept = true;}});
  91. if(afAccept === false){
  92. $("#ErrUpload").removeClass('d-none').addClass('d-block')
  93. $("#ErrUpload").html(ext.labelAcceptFiles + ' : <b>' + ext.acceptFiles + ' :</b> <span class="text-danger">'+ file.name+ ' </span><b>'+ ext.labelAllDenied +'</b>');
  94. }
  95. }else{afAccept = true;}
  96. //Option max size
  97. if(parseInt(ext.maxFileSize) > parseInt(file.size)){mfsAccept = true;}else{
  98. $("#ErrUpload").removeClass('d-none').addClass('d-block')
  99. $("#ErrUpload").html(ext.labelMaxFileSize + ' : <b>' + Math.round((ext.maxFileSize / 1000000)*100)/100 + 'Mo :</b> <span class="text-danger">'+ file.name+ ' </span><b>'+ ext.labelAllDenied +'</b>');
  100. mfsAccept = false;
  101. }
  102. //Option max files
  103. if(parseInt(postfiles.length) < parseInt(ext.maxFileCount)){mfcAccept = true;}else{
  104. $("#ErrUpload").removeClass('d-none').addClass('d-block')
  105. $("#ErrUpload").html(ext.labelMaxFileCount + ' : <b>' + ext.maxFileCount);
  106. mfcAccept = false;
  107. }
  108. var doublon = Object.keys(postfiles).some(function(k) {return postfiles[k] === file.name;});
  109. if(doublon === false && afAccept === true && mfsAccept === true && mfcAccept === true){
  110. postfiles.push(file.name);
  111. const reader = new FileReader();
  112. reader.onload = (e) => {
  113. var $LastModified = new Date(file.lastModified).toISOString().split('T')[0]
  114. var ReaderResultat= pat.imgPath + ext.defaultImg;
  115. Object.keys($mimeType).forEach(m => {
  116. if($mimeType[m].type === file.type){
  117. switch ($mimeType[m].source) {
  118. case 'img' :ReaderResultat = reader.result;break;
  119. case 'no-img' :ReaderResultat;break;
  120. default :ReaderResultat = pat.imgPath + $mimeType[m].source;
  121. }
  122. }
  123. })
  124. $(".gallery").append('\
  125. <li class="border border-right-0 border-top-0 border-success shadow py-1 mb-1" style="border-width:3px !important;">\
  126. <img src="'+ ReaderResultat +'" class="rounded p-2" height="100" width="100">\
  127. <div class="p-2">\
  128. <h6 class="text-break">'+ ext.labelName +': '+ file.name+'</h6>\
  129. <h6 class="text-break">'+ ext.labelType +': '+ file.type +'</h6>\
  130. <h6 class="text-break">'+ ext.labelModified +': '+ new Date(file.lastModified).toISOString().split('T')[0] +'</h6>\
  131. <h6 class="text-break">'+ ext.labelSize +': '+ Math.round((file.size / 1000000)*100)/100 +' Mo</h6>\
  132. <button data-id="'+ file.name +'" class="btn btn-danger Erase">'+ ext.labelDeleteBtn +'</button>\
  133. </div>\
  134. </li>\
  135. ')
  136. }
  137. reader.readAsDataURL(file);
  138. }
  139. })
  140. if(postfiles.length === 0){
  141. $("#SaveFiles").removeClass('d-block').addClass('d-none');
  142. $(".custom-file-label").html(ext.labelInput1);
  143. }else{
  144. $("#SaveFiles").removeClass('d-none').addClass('d-block');
  145. $(".custom-file-label").html(ext.labelInput2 + ': ' + postfiles.length);
  146. }
  147. });
  148. //Delete File
  149. $("div ul").on("click", ".Erase", function(){
  150. DataId = $(this).attr('data-id');
  151. tmp_postfiles = [];
  152. Object.keys(postfiles).forEach(i => {
  153. if(DataId != postfiles[i]){tmp_postfiles.push(postfiles[i]);}
  154. })
  155. postfiles = tmp_postfiles;
  156. $(this).parent().parent().remove();
  157. if(postfiles.length === 0){
  158. $("#SaveFiles").removeClass('d-block').addClass('d-none');
  159. $("#ErrUpload").removeClass('d-block').addClass('d-none');
  160. $(".custom-file-label").html(ext.labelInput1);
  161. }else{
  162. $("#SaveFiles").removeClass('d-none').addClass('d-block');
  163. $(".custom-file-label").html(ext.labelInput2 + ': ' + postfiles.length);
  164. }
  165. <p></p>
infoPhp = [];
postfiles = [];
formData = new FormData();

$(function() {

    $.fn.swallow = function (options){

    //Config path by default
        var pat = $.extend({
            imgPath             : "img/",
            phpPath             : "php/",         
            targetPath          : "nest/"
        }, options);   

    //Search on the PHP server configuration items
        $.ajax({url:pat.phpPath + 'info.php',async:false,
            success: (s) => {infoPhp.push(JSON.parse(s));},
            error: () => {alert('require ==> info.php');return false;},
        })

    //Config options user
        var ext = $.extend({ 
            swallowTag          : false,   
            targetTag           : infoPhp[0]['tag_swallow'],            
            method              : "POST",
            enctype             : "multipart/form-data",
            acceptFiles         : "*",
            maxFileSize         : infoPhp[0]['upload_max_filesize'],
            maxFileCount        : infoPhp[0]['max_file_uploads'],
            postMaxSize         : infoPhp[0]['post_max_size'],
            maxImgQuality       : 100,
            defaultImg          : "file.png",
            labelInput1         : "Add your files",
            labelInput2         : "Number of files",
            labelName           : "Name",
            labelType           : "Type file",
            labelModified       : "Modified",
            labelSize           : "Size",
            labelSaveBtn        : "Save",
            labelDeleteBtn      : "Delete",
            labelLoadingBtn     : "Loading...",
            labelSuccess        : "File upload successful",
            labelAcceptFiles    : "Accepted formats",
            labelMaxFileSize    : "Max size accept",
            labelMaxFileCount   : "Max files accept",
            labelAllDenied      : "Denied !",
            onSuccess           : function (response, statut) {},
            onError             : function (response, statut, erreur) {}
        }, options);

        

    //Form input bootstrap 4
        $(this).append('\
        <div class="row">\
            <div class="col-12 mb-2">\
                <form method="post" enctype="'+ ext.enctype +'">\
                    <div class="alert alert-danger d-none fade show" role="alert" id="ErrUpload"></div>\
                        <div class="custom-file">\
                            <input type="file" class="custom-file-input" id="swallow" name="swallow[]" multiple>\
                            <label class="custom-file-label" for="swallow">'+ ext.labelInput1 +'</label>\
                        </div>\
                        <div class="mt-1">\
                            <button class="btn btn-block btn-success d-none" id="SaveFiles" type="button">'+ ext.labelSaveBtn +'</button>\
                            <button class="btn btn-block btn-info WaitSpinner d-none" disabled><span class="spinner-grow spinner-grow-sm"></span> '+ ext.labelLoadingBtn +'</button>\
                        </div>\
                </form>\
            </div>\
            <div class="col-12 mt-2">\
                <ul class="list-unstyled gallery"></ul>\
                <div class="toast d-none" aria-atomic="true" data-delay="2000" id="SuccUpload">\
                <div class="toast-header">\
                <img src="'+ pat.imgPath + ext.defaultImg +'" class="rounded mr-2" height="15" width="15">\
                <strong class="mr-auto">Swallow</strong>\
                <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">\
                  <span aria-hidden="true">&times;</span>\
                </button>\
                </div>\
                <div class="toast-body">'+ ext.labelSuccess +'</div>\
                </div>\
            </div>\
        </div>\
        ')

    //Tag file or multiple files
        $("#swallow").on("change", function(e) {

            const files = e.currentTarget.files;
            $("#ErrUpload").empty().removeClass('d-block').addClass('d-none');
            $("#SaveFiles").removeClass('d-block').addClass('d-none');

        //Defaut save formData
            $.each($(this)[0].files, function(i, file) {formData.append('swallow[]', file);});

            Object.keys(files).forEach(i => {

                const file = files[i];

            //Option type files
                if(ext.acceptFiles != "*"){
                    afAccept = false;
                    afArray = ext.acceptFiles.split(',');
                    afArray.forEach(element => {if(file.type === element){afAccept = true;}});
                        if(afAccept === false){
                            $("#ErrUpload").removeClass('d-none').addClass('d-block')
                            $("#ErrUpload").html(ext.labelAcceptFiles + ' : <b>' + ext.acceptFiles + ' :</b> <span class="text-danger">'+ file.name+ ' </span><b>'+ ext.labelAllDenied +'</b>');                        
                        }
                }else{afAccept = true;}

            //Option max size
                if(parseInt(ext.maxFileSize) > parseInt(file.size)){mfsAccept = true;}else{
                    $("#ErrUpload").removeClass('d-none').addClass('d-block')
                    $("#ErrUpload").html(ext.labelMaxFileSize + ' : <b>' + Math.round((ext.maxFileSize / 1000000)*100)/100 + 'Mo :</b> <span class="text-danger">'+ file.name+ ' </span><b>'+ ext.labelAllDenied +'</b>');                    
                    mfsAccept = false;
                }

            //Option max files
                if(parseInt(postfiles.length) < parseInt(ext.maxFileCount)){mfcAccept = true;}else{
                    $("#ErrUpload").removeClass('d-none').addClass('d-block')
                    $("#ErrUpload").html(ext.labelMaxFileCount + ' : <b>' + ext.maxFileCount);                    
                    mfcAccept = false;
                }

                var doublon = Object.keys(postfiles).some(function(k) {return postfiles[k] === file.name;});

                if(doublon === false && afAccept === true && mfsAccept === true && mfcAccept === true){
                    
                    postfiles.push(file.name);

                    const reader = new FileReader();
                    
                    reader.onload = (e) => {

                        var $LastModified = new Date(file.lastModified).toISOString().split('T')[0]
                        var ReaderResultat= pat.imgPath + ext.defaultImg;                        
                        Object.keys($mimeType).forEach(m => {
                            if($mimeType[m].type === file.type){
                                switch ($mimeType[m].source) {
                                    case 'img'          :ReaderResultat = reader.result;break;
                                    case 'no-img' :ReaderResultat;break;
                                    default          :ReaderResultat = pat.imgPath + $mimeType[m].source;
                                }
                            }
                        })
              
                        $(".gallery").append('\
                            <li class="border border-right-0 border-top-0 border-success shadow py-1 mb-1" style="border-width:3px !important;">\
                                <img src="'+ ReaderResultat +'" class="rounded p-2" height="100" width="100">\
                                <div class="p-2">\
                                <h6 class="text-break">'+ ext.labelName +': '+ file.name+'</h6>\
                                <h6 class="text-break">'+ ext.labelType +': '+ file.type +'</h6>\
                                <h6 class="text-break">'+ ext.labelModified +': '+ new Date(file.lastModified).toISOString().split('T')[0] +'</h6>\
                                <h6 class="text-break">'+ ext.labelSize +': '+ Math.round((file.size / 1000000)*100)/100 +' Mo</h6>\
                                <button data-id="'+ file.name +'" class="btn btn-danger Erase">'+ ext.labelDeleteBtn +'</button>\
                                </div>\
                            </li>\
                        ')

                    }
                        
                    reader.readAsDataURL(file);
                }
                
            })

            if(postfiles.length === 0){
                $("#SaveFiles").removeClass('d-block').addClass('d-none');
                $(".custom-file-label").html(ext.labelInput1);
            }else{
                $("#SaveFiles").removeClass('d-none').addClass('d-block');
                $(".custom-file-label").html(ext.labelInput2 + ': ' + postfiles.length);
            }

        });
        
    //Delete File
        $("div ul").on("click", ".Erase", function(){

            DataId = $(this).attr('data-id');
            tmp_postfiles = [];

            Object.keys(postfiles).forEach(i => {
                if(DataId != postfiles[i]){tmp_postfiles.push(postfiles[i]);}
            })

            postfiles = tmp_postfiles;

            $(this).parent().parent().remove();

            if(postfiles.length === 0){
                $("#SaveFiles").removeClass('d-block').addClass('d-none');
                $("#ErrUpload").removeClass('d-block').addClass('d-none');
                $(".custom-file-label").html(ext.labelInput1);
            }else{
                $("#SaveFiles").removeClass('d-none').addClass('d-block');
                $(".custom-file-label").html(ext.labelInput2 + ': ' + postfiles.length);
            }

        <p></p>
                                                
站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 图片特效&上传

CSS实现的鼠标悬停图片弹出放大特效代码

一款图片放大动画特效代码,鼠标放置在图片缩略图上时,触发当前图片弹出放大效果,鼠标移走后消失。
  图片特效&上传
 6393  0

swiper全屏响应式图片滑动展示特效代码

一款支持触屏滑动的图片展示特效,可左右滑动切换显示不同的图片,而且图片鼠标悬停显示标题文本文字。
  图片特效&上传
 1512  0

jquery多张图片上传预览插件

可限制上传图片数量,以及上传的图片尺寸大小,都可自定义。
  图片特效&上传
 5371  0

jquery响应式支持触屏滑动切换的图片弹出层查看器

一款图片弹出层可左右切换特效代码,支持图片、视频弹出显示,自动关联上一张或下一张可点击切换或关闭。
  图片特效&上传
 6355  0

评论数(1) 回复有机会获得K币 用户协议

    great0
    2023-12-12 15:59:09
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论