JQuery文件上传,它去哪儿了?

 透明的眼泪2502913707 发布于 2023-02-11 12:03

我一直在关注使用JQuery文件上传插件的本教程.一切看起来都很好,当我选择一个文件上传浏览器没有错误,但文件似乎没有上传.我可能错了,但我认为该文件将uploads位于项目目录(eclipse)中的文件夹中.这是代码:

的index.html




    
        
        Mini Ajax File Upload Form

        
        

        
        
    

    

        
Drop Here Browse

的script.js

$(function(){

    var ul = $('#upload ul');

    $('#drop a').click(function(){
        // Simulate a click on the file input button
        // to show the file browser dialog
        $(this).parent().find('input').click();
    });

    // Initialize the jQuery File Upload plugin
    $('#upload').fileupload({

        // This element will accept file drag/drop uploading
        dropZone: $('#drop'),

        // This function is called when a file is added to the queue;
        // either via the browse button, or via drag/drop:
        add: function (e, data) {

            var tpl = $('
  • '); // Append the file name and file size tpl.find('p').text(data.files[0].name) .append('' + formatFileSize(data.files[0].size) + ''); // Add the HTML to the UL element data.context = tpl.appendTo(ul); // Initialize the knob plugin tpl.find('input').knob(); // Listen for clicks on the cancel icon tpl.find('span').click(function(){ if(tpl.hasClass('working')){ jqXHR.abort(); } tpl.fadeOut(function(){ tpl.remove(); }); }); // Automatically upload the file once it is added to the queue var jqXHR = data.submit(); }, progress: function(e, data){ // Calculate the completion percentage of the upload var progress = parseInt(data.loaded / data.total * 100, 10); // Update the hidden input field and trigger a change // so that the jQuery knob plugin knows to update the dial data.context.find('input').val(progress).change(); if(progress == 100){ data.context.removeClass('working'); } }, fail:function(e, data){ // Something has gone wrong! data.context.addClass('error'); } }); // Prevent the default action when a file is dropped on the window $(document).on('drop dragover', function (e) { e.preventDefault(); }); // Helper function that formats the file sizes function formatFileSize(bytes) { if (typeof bytes !== 'number') { return ''; } if (bytes >= 1000000000) { return (bytes / 1000000000).toFixed(2) + ' GB'; } if (bytes >= 1000000) { return (bytes / 1000000).toFixed(2) + ' MB'; } return (bytes / 1000).toFixed(2) + ' KB'; } });

    upload.php的

    
    
    

    所有其他所需的js文件也存在.当我在tomcat上运行它时,我的输出如下所示:

    浏览器视图/控制台输出/项目结构

    我也刷新了这个项目,所以不是这样.任何帮助都会很棒,谢谢.

    撰写答案
    今天,你开发时遇到什么问题呢?
    立即提问
    热门标签
    PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
    Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有