Home Web Front-end JS Tutorial Real-time display of progress bar for uploading images based on Jquery plug-in Uploadify_jquery

Real-time display of progress bar for uploading images based on Jquery plug-in Uploadify_jquery

May 16, 2016 am 09:00 AM
jquery upload image plug-in progress bar

first learn about uploadify, the details are as follows

uploadify is a simple and easy-to-use multi-file upload solution. as a jquery plug-in, uploadify is simple to use and highly customizable.

uploadify features:

to put it simply, uploadify is a file upload plug-in based on jquery. its functional features are summarized as follows:

1), supports single file or multiple file uploads, and can control the number of files uploaded concurrently
2) support various languages ​​for use on the server side, such as php, .net, java...
3). upload file type and size limit can be configured through parameters
4) whether to automatically upload files after selecting them can be configured through parameters
5), easy to expand, can control the callback function of each step (onselect, oncancel...)
6). control appearance through interface parameters and css
7) provide event callbacks for upload progress and display upload progress in real time
8) before starting, you need to download the plug-in installation package locally and reference it. please see the code comments for detailed implementation. start the code below.

1. html code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

<div id="webapplogo_file" style="display: block; width: 800px; background-color: #fff;">

      <ul>

        <li style="margin-left: 213px;"><span class="black_blod14">logo图标:</span></li>

        <li style="margin-left: 3px;">

          <input type="text" readonly="readonly" id="text_webapplogo" name="app_logo" class="appipt1" value="<%=applogo %>" /></li>

        <li style="padding-top: 1px;">

          <input type="file" id="webapplogo" name="webapplogo" />

        </li>

        <li><span style="display: none; margin-left: 5px; padding-left: 20px; color: #ea5200;

          font-size: 12px; background: url('images/icon_03.gif' ) no-repeat 0px 0px;" id="textporapplogo">

          请上传logo图标!</span></li>

        <li style="margin-left: 220px;"><span class="grey999" style="margin-left: 90px; float: left;">

          尺寸72px*72px,png格式,建议使用 图标psd模板 制作</span>

          <div id="qid_webapplogo" class="filequeue"></div>

          <table id="webapplogo_tab" width="50%" border="0" cellspacing="0" cellpadding="0"

            align="center" class="grey999" style="display: none; margin-left: 90px; float: left;">

            <tr>

              <td align="center" valign="bottom">

                <img  src="/static/imghw/default1.png"  data-src="images/icon_02.gif"  class="lazy"    style="max-width:90%" id="img_64" border="0" / alt="Real-time display of progress bar for uploading images based on Jquery plug-in Uploadify_jquery" ><br />

                (64*64)

              </td>

              <td align="center" valign="bottom">

                <img  src="/static/imghw/default1.png"  data-src="images/icon_02.gif"  class="lazy"    style="max-width:90%" id="img_48" border="0" / alt="Real-time display of progress bar for uploading images based on Jquery plug-in Uploadify_jquery" ><br />

                (48*48)

              </td>

              <td align="center" valign="bottom">

                <img  src="/static/imghw/default1.png"  data-src="images/icon_02.gif"  class="lazy"    style="max-width:90%" id="img_32" border="0" / alt="Real-time display of progress bar for uploading images based on Jquery plug-in Uploadify_jquery" ><br />

                (32*32)

              </td>

              <td align="center" valign="bottom">

                <img  src="/static/imghw/default1.png"  data-src="images/icon_02.gif"  class="lazy"    style="max-width:90%" id="img_16" border="0" / alt="Real-time display of progress bar for uploading images based on Jquery plug-in Uploadify_jquery" ><br />

                (16*16)

              </td>

            </tr>

          </table>

        </li>

      </ul>

    </div>

Copy after login

2. javascript code (key part)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

$("#webapplogo").uploadify({

      'uploader': 'js/uploadify-v2.1.4/uploadify.swf',//进度条,uploadify里面含有

      'script': 'uploadapplogo.ashx',//一般处理程序

      'cancelimg': 'js/uploadify-v2.1.4/cancel.png',//取消图片路径

      'folder': 'imagelogo',//上传文件夹名

      'auto': true, //文件添加到上传队列后,自动进行上传。默认为false

      'multi': false,//是否允许多文件上传。默认为false

      'fileext':'*.gif;*.jpg;*.jpeg;*.png',//允许上传的文件类型,使用分号(”;)”分割 例如:*.jpg;*.gif,默认为null(所有文件类型)

      'filedesc':'不超过2m的图片 (*.gif;*.jpg;*.png)',

      'sizelimit': 2048000, //允许上传的文件大小(kb) 此为2m

      'onselectonce': function(event,data) { //在单文件或多文件上传时,选择文件时触发

        //event 事件对象(the event object)

        //data 选择的操作信息

        //data.filesselected 选择文件操作中选中的文件数量

        $('#status-message').text(data.filesselected + ' 文件正在等待上传…….');

      },

      'oncomplete': function(event, queueid, fileobj, response, data) {//当单个文件上传完成后触发

        //event:事件对象(the event object)

        //id:该文件在文件队列中的唯一表示

        //fileobj:选中文件的对象,他包含的属性列表

        //response:服务器端返回的response文本,我这里返回的是处理过的文件名称

        //data:文件队列详细信息和文件上传的一般数据

 

        alert("文件:" + fileobj.name + " 上传成功!");

        //设置图片名称

        $("#applogo").attr("value",response);

        //设置输入框的值

        $("#text_webapplogo").attr("value",fileobj.name);

        //设置图片路径

        $("#img_64").attr("src","imagelogo/64_"+response);

        $("#img_48").attr("src","imagelogo/48_"+response);

        $("#img_32").attr("src","imagelogo/32_"+response);

        $("#img_16").attr("src","imagelogo/16_"+response);

        //图片路径设置完成后,显示图片

        $("#webapplogo_tab").css("display","block");

      },

      'onerror': function(event, queueid, fileobj) {//当单个文件上传出错时触发

        alert("文件:" + fileobj.name + " 上传失败!");

      },

      'buttonimg':'images/bn_04.gif',//浏览按钮的图片路径

      'width':60,//浏览按钮的宽和高

      'height':24

      ,'queueid':'qid_webapplogo'//页面上作为文件上传队列的元素的id

    });

Copy after login

3. server-side processing of file uploads

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

/// <summary>

  /// 上传文件

  /// </summary>

  public class UploadApplogo : IHttpHandler

  {

    System.Drawing.Image image, image64, image48, image32, image16; //定义image类的对象

    protected string imagePath;//图片路径

    protected string imageType;//图片类型

    protected string imageName;//图片名称

    protected string fileName;//图片名称

    //提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行

    //如果此方法确定 GetThumbnailImage 方法应提前停止执行,则返回 true;否则返回 false

    System.Drawing.Image.GetThumbnailImageAbort callb = null;

 

    public void ProcessRequest(HttpContext context)

    {

      context.Response.ContentType = "text/plain";

      HttpPostedFile UploadImage = context.Request.Files["FileData"];

      //物理路径

      string uploadpath = HttpContext.Current.Server.MapPath(context.Request["folder"] + "\\");

 

      if (UploadImage != null)

      {

        //是否有目录,如没有就创建

        if (!Directory.Exists(uploadpath))

        {

          Directory.CreateDirectory(uploadpath);

        }

        //客户端文件完全名称

        string filename = UploadImage.FileName;

        string extname = filename.Substring(filename.LastIndexOf(".") + 1);

        //为不重复,设置文件名

        fileName = Guid.NewGuid().ToString() + "." + extname;

 

        //context.Response.Write("1");

        context.Response.Write(fileName);

      }

      else

      {

        context.Response.Write("0");

      }

 

      string mPath;     

 

      imagePath = UploadImage.FileName;

      //取得图片类型

      imageType = imagePath.Substring(imagePath.LastIndexOf(".") + 1);

      //取得图片名称

      imageName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1);

      Stream imgStream = UploadImage.InputStream;//流文件,准备读取上载文件的内容

      int imgLen = UploadImage.ContentLength;//上载文件大小

 

      //建立虚拟路径

      mPath = HttpContext.Current.Server.MapPath(context.Request["folder"]);

      //保存到虚拟路径

      UploadImage.SaveAs(mPath + "\\" + fileName);

      ////显示原图

      //imageSource.ImageUrl = "upFile/" + imageName;

      //为上传的图片建立引用

      image = System.Drawing.Image.FromFile(mPath + "\\" + fileName);

 

      //生成缩略图

      image64 = image.GetThumbnailImage(64, 64, callb, new System.IntPtr());

      //把缩略图保存到指定的虚拟路径

      image64.Save(HttpContext.Current.Server.MapPath(context.Request["folder"]) + "\\64_" + fileName);

      //释放image64对象的资源

      image64.Dispose();

 

      //生成缩略图

      image48 = image.GetThumbnailImage(48, 48, callb, new System.IntPtr());

      image48.Save(HttpContext.Current.Server.MapPath(context.Request["folder"]) + "\\48_" + fileName);

      image48.Dispose();

 

      //生成缩略图

      image32 = image.GetThumbnailImage(32, 32, callb, new System.IntPtr());

      image32.Save(HttpContext.Current.Server.MapPath(context.Request["folder"]) + "\\32_" + fileName);

      image32.Dispose();

 

      //生成缩略图

      image16 = image.GetThumbnailImage(16, 16, callb, new System.IntPtr());

      image16.Save(HttpContext.Current.Server.MapPath(context.Request["folder"]) + "\\16_" + fileName);

      image16.Dispose();

 

      //释放image对象占用的资源

      image.Dispose();

    }

 

    public bool IsReusable

    {

      get

      {

        return false;

      }

    }

  }

Copy after login

4. the effect is as follows

the above is the entire content of this article, i hope it will be helpful to everyone's study.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the Chrome plug-in extension installation directory? What is the Chrome plug-in extension installation directory? Mar 08, 2024 am 08:55 AM

What is the Chrome plug-in extension installation directory? Under normal circumstances, the default installation directory of Chrome plug-in extensions is as follows: 1. The default installation directory location of chrome plug-ins in windowsxp: C:\DocumentsandSettings\username\LocalSettings\ApplicationData\Google\Chrome\UserData\Default\Extensions2. chrome in windows7 The default installation directory location of the plug-in: C:\Users\username\AppData\Local\Google\Chrome\User

Share three solutions to why Edge browser does not support this plug-in Share three solutions to why Edge browser does not support this plug-in Mar 13, 2024 pm 04:34 PM

When users use the Edge browser, they may add some plug-ins to meet more of their needs. But when adding a plug-in, it shows that this plug-in is not supported. How to solve this problem? Today, the editor will share with you three solutions. Come and try it. Method 1: Try using another browser. Method 2: The Flash Player on the browser may be out of date or missing, causing the plug-in to be unsupported. You can download the latest version from the official website. Method 3: Press the "Ctrl+Shift+Delete" keys at the same time. Click "Clear Data" and reopen the browser.

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on ​​the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to unblock Google Chrome plug-in How to unblock Google Chrome plug-in Apr 01, 2024 pm 01:41 PM

How to unblock the Google Chrome plug-in? Many users like to install various useful plug-ins when using Google Chrome. These plug-ins can provide rich functions and services and improve work efficiency. However, some users say that after installing plug-ins in Google Chrome, the plug-ins will always be displayed. is blocked, so how can you unblock the plug-in after encountering this situation? Now let the editor show you the steps to unblock plug-ins in Google Chrome. Friends in need should come and take a look. How to unblock plug-ins in Google Chrome Step 1. When the blocked prompt appears, click the "Control Bar" and select "Install ActiveX Control". 2. Then open the browser "Tools" menu and click "Internet Options". 3.

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

See all articles