Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 349|回复: 0

[默认分类] jquery File upload使用总结

[复制链接]
  • TA的每日心情
    开心
    2021-12-13 21:45
  • 签到天数: 15 天

    [LV.4]偶尔看看III

    发表于 2018-6-1 10:20:18 | 显示全部楼层 |阅读模式


    1. jquery file upload 下载
    jquery file upload Demo 地址:https://blueimp.github.io/jQuery-File-Upload/

    jquery file upload 下载   地址:https://github.com/blueimp/jQuery-File-Upload/tags

    jquery file upload API    地址:https://github.com/blueimp/jQuery-File-Upload/wiki/API
    2. jquery file upload 样式
    使用了bootstrap框架,样式可以参考Demo。


    自定义的样式:

    1. <div class="row fileupload-buttonbar" style="padding-left:15px;">
    2. <div class="thumbnail col-sm-6">
    3. <img id="weixin_show" style="height:180px;margin-top:10px;margin-bottom:8px;"  src="__PUBLIC__/images/game/game_1.png" data-holder-rendered="true">
    4. <div class="progress progress-striped active" role="progressbar" aria-valuemin="10" aria-valuemax="100" aria-valuenow="0"><div id="weixin_progress" class="progress-bar progress-bar-success" style="width:0%;"></div></div>
    5. <div class="caption" align="center">
    6. <span id="weixin_upload" class="btn btn-primary fileinput-button">
    7. <span>上传</span>
    8. <input type="file" id="weixin_image" name="weixin_image" multiple>
    9. </span>
    10. <a id="weixin_cancle" href="javascript:void(0)" class="btn btn-warning" role="button" onclick="cancleUpload("weixin")" style="display:none">删除</a>
    11. </div>
    12. </div>
    13. </div>
    复制代码

    需要引入的js、css文件

    1.     <link href="__PUBLIC__/css/bootstrap.min.css" rel="stylesheet">
    2.     <!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
    3.     <link rel="stylesheet" href="__PUBLIC__/css/jquery.fileupload.css">
    4.     <link rel="stylesheet" href="__PUBLIC__/css/jquery.fileupload-ui.css">
    5.     <script src="__PUBLIC__/js/jquery.min.js"></script>
    6.     <script src="__PUBLIC__/js/vendor/jquery.ui.widget.js"></script>
    7.     <script src="__PUBLIC__/js/jquery.fileupload.js"></script>
    8.     <script src="__PUBLIC__/js/jquery.iframe-transport.js"></script>
    复制代码

    调用方式:

    1. $(function() {
    2.         $("#weixin_image").fileupload({
    3.                     url: "__CONTROLLER__/uploadImg",
    4.                     sequentialUploads: true
    5.             }).bind("fileuploadprogress", function (e, data) {
    6.                     var progress = parseInt(data.loaded / data.total * 100, 10);
    7.                     $("#weixin_progress").css("width",progress + "%");
    8.                     $("#weixin_progress").html(progress + "%");
    9.             }).bind("fileuploaddone", function (e, data) {
    10.                     $("#weixin_show").attr("src","__PUBLIC__/"+data.result);
    11.                     $("#weixin_upload").css({display:"none"});
    12.                     $("#weixin_cancle").css({display:""});
    13.             });
    14.                   
    15.         });
    复制代码

    url:后台提交的地址
    fileuploadprogress:主要是进度条的修改

    fileuploaddone:上传结束后执行的操作

    3. 后台执行的代码
    使用的thinkphp代码,上传代码很简单

    1. public function uploadImg(){
    2.         $upload = new \Think\Upload();// 实例化上传类
    3.         $upload->maxSize   =     3145728 ;// 设置附件上传大小
    4.         //$upload->exts      =     array("jpg", "gif", "png", "jpeg");// 设置附件上传类型
    5.         $upload->rootPath  =      "./Public/Uploads/"; // 设置附件上传根目录
    6.         $upload->savePath  =      ""; // 设置附件上传(子)目录
    7.         
    8.         // 上传文件
    9.         $info   =   $upload->uploadOne($_FILES["weixin_image"]);
    10.         if(!$info) {// 上传错误提示错误信息
    11.             //$this->error($upload->getError());
    12.             echo 0;
    13.         }else{// 上传成功 获取上传文件信息
    14.             //$this->display("templateList");
    15.             echo "Uploads/".$info["savepath"].$info["savename"];
    16.         }
    17.     }
    复制代码






    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2025-5-17 20:31 , Processed in 0.748255 second(s), 37 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表