Ошибка 404 К сожалению, такой страницы нет.

я есть несколько файлов загрузки, здесь я показываю количество файлов и размер файла (до 3 ГБ) во время загрузки, при удалении файла я не могу обновить количество оставшихся файлов и размер файла.

Запись: если я удаляю и добавляю больше файлов, то также показываю неправильный счет

Вот код

<span class="form-field" style="margin-top:28px;">       
            <p class="contact"><label for="">File attachments</label></p> 
            <div class="image-upload" id="image-upload">
                <span id="file_labels_div">                
                    <div class="div-file" id="div-file-1">
                        <label for="input-file-1" style="cursor: pointer;">
                            <img style="vertical-align:middle; margin-right: 15px;" width="50px" id="fileupload-attachments" src="<?= SITE_URL ?>views/images/plus_icon.png" /> FILE ATTACHMENTS UP TO 3GB 
                        </label>
                        <input id="input-file-1" name="projectfiles[]" inc="1" onchange="getFileName(this);"  style="cursor: pointer; visibility: hidden;" type="file"/>
                    </div>
                </span>
                <div class="all-filenames-span" id="all-filenames"></div>
            </div>
</span> 

Вот мой JQuery / Javascript код

var SITE_URL = "";
var increaseFile = 2, filecheck = 1, filesize = 0, total_file_size = '';
function getFileName(fileobj) {

    checkfiles();
    if (filesize > 3204448256) {
        alert('Your files contains more than 3GB..please upload upto 3GB')
    }

    if (filecheck == 2) {
        $("#div-file-" + $("#" + fileobj.id + "").attr('inc')).hide();
        $("#file_labels_div").append('<div class="div-file" id="div-file-' + increaseFile + '"><label for="input-file-' + increaseFile + '"><img style="vertical-align:middle; margin-right: 15px;" id="fileupload-attachments" src="' + SITE_URL + 'views/images/plus_icon.png" width="50px" /><span id="img_label" >' + total_file_size + '</span></label><input id="input-file-' + increaseFile + '" name="projectfiles[]" inc="' + increaseFile + '" onchange="getFileName(this);"  style="display:none;" type="file"/></div>');
        increaseFile++;
    } else {
        $("#file_labels_div").html('<div class="div-file" id="div-file-1"><label for="input-file-1"><img style="vertical-align:middle; margin-right: 15px;" id="fileupload-attachments" src="' + SITE_URL + 'views/images/plus_icon.png" width="50px" /><span id="img_label" >FILE ATTACHMENTS UP TO 3GB</span></label><input id="input-file-1" name="projectfiles[]" inc="1" onchange="getFileName(this);"  style="display:none;" type="file"/></div><span id="all-filenames"></span>');
        increaseFile = 2;
        filesize = 0;
    }
}


function checkfiles() {
    //file_names='<span id="all-filenames">';
    file_names = '';
    filesize = 0;
    filecheck = 1;

    for (fcheck = 0; fcheck < increaseFile; fcheck++) {
        if ($('#div-file-' + fcheck).length > 0)
        {

            var x = document.getElementById("input-file-" + fcheck);
            var txt = "";
            myFile = "input-file-" + fcheck + "";
            if ('files' in x) {
                //alert(x.files.length)
                if (x.files.length == 0) {
                    txt = "Select one or more files.";
                } else {

                    filecheck = 2;
                    for (var i = 0; i < x.files.length; i++) {
                        //txt += "<br><strong>" + (i+1) + ". file</strong><br>";
                        var file = x.files[i];
                        if ('name' in file) {
                            // txt += "name: " + file.name + "<br>";
                            if (filesize > 3204448256)
                            {
                                $("#all-filenames").html(file_names);
                                //alert("You have exceeded maximum allowed size 3GB")
                                return true;
                            }

                            if ('size' in file) {
                                var sizeInMB = (file.size / (1024 * 1024)).toFixed(2);
                            }

                            //alert(sizeInMB + 'MB');

                            // file_names+='<span onmouseover=\'$("#closebtn-'+fcheck+'").show()\' onmouseout=\'$("#closebtn-'+fcheck+'").hide()\' id="singlefile-'+fcheck+'">'+file.name+' ('+sizeInMB+'MB) <img id="closebtn-'+fcheck+'"  src="images/x-close_btn.png" style="cursor:pointer;/*display:none;*/vertical-align: bottom;padding-left: 3px;" onclick=deletefile("singlefile-'+fcheck+'","#div-file-'+fcheck+'") /> <br></span>';
                            file_names += '<div class="singlefile"  id="singlefile-' + fcheck + '"><img id="closebtn-' + fcheck + '"  src="' + SITE_URL + 'views/images/[email protected]" width="50px" style="cursor:pointer;/*display:none;*/vertical-align: middle;padding-left: 12px; margin-right: 18px; width: 15px;" onclick=deletefile("singlefile-' + fcheck + '","#div-file-' + fcheck + '") />' + file.name + ' (' + sizeInMB + 'MB)<br></div><input id="input-file-' + increaseFile + '" name="projectfiles[]" inc="' + increaseFile + '" onchange="getFileName(this);"  style="display:none;" type="file"/>';
                        }
                        if ('size' in file) {
                            // txt += "size: " + file.size + " bytes <br>";
                            filesize += file.size
                        }
                    }
                }
            }

            //file_names+='</span>';

            //$( "span" ).remove( "#all-filenames" );
            //  $("#all-filenames").remove();

            $("#all-filenames").html(file_names)
            //  alert('>>>'+txt)

        }
    }

    var sizeInMB = (filesize / (1024 * 1024)).toFixed(2);
    total_file_size = (fcheck - 1) + " ATTACHMENTS / (" + (3000 - sizeInMB) + "MB REMAINING)";
//              $("#div-file-"+fcheck).html(total_file_size)    


}

function deletefile(filename, divname)
{
//  alert('file name is'+filename+"divname"+divname)
    $('#' + filename).remove();
    $(divname).remove();

    checkfiles();
    if (filecheck == 1)
    {
        $("#file_labels_div").html('<div class="div-file" id="div-file-1"><label for="input-file-1"><img style="vertical-align:middle; margin-right: 15px;" id="fileupload-attachments" src="' + SITE_URL + 'views/images/plus_icon.png" width="50px" /> FILE ATTACHMENTS UP TO 3GB</label><input id="input-file-1" name="projectfiles[]" inc="1" onchange="getFileName(this);"  style="visibility: hidden;" type="file"/></div>');
        $('#image-upload').append('<div class="all-filenames-span" id="all-filenames"></div>');
        increaseFile = 2;
        filesize = 0;
    }

}

Спасибо за все предложения Вот рабочий код скрипки

https://fiddle.jshell.net/vijayak7803/vt5b0exw/15/

Ответы на вопрос(0)

Ваш ответ на вопрос