Home Web Front-end JS Tutorial Implementation of limiting the number of uploadify uploads in js

Implementation of limiting the number of uploadify uploads in js

Jun 25, 2018 pm 02:26 PM

This article will share with you how to limit the number of uploads when using uploadify to upload files or images. It is very simple, convenient and practical. Friends in need can refer to it.

Simple implementation of limiting the number of uploadify uploads

function deleteUrl(){
   $("body").on("click",".img-wrap .mask span",function(event){
    event.stopPropagation();
          
    var qs=$('#file_upload-queue>p');//所有的队列
    var id=qs.eq(2).attr('id');//得到第三个队列的id
    $('#uploadTowedAccredit').uploadify('cancel',id);//这样就行了,会自动重置队列数量和删除dom对象,不能直接qs.eq(2).remove(),无效
      
    /*
    if(!window.confirm("您确定删除附件?")){
      return;
    }
    var imgUrl=$(this).parents(".img-wrap").find("img").attr("src");
    deleteImage(imgUrl);
    $(this).parents(".img-wrap").remove();
    */
  });
};
Copy after login

##

<li class="blockli clearfix" style="padding-bottom: 5px;">
  <span class="left-name"><em class="red-star">*</em>拖机授权委托书:</span>
  <p class="upload-wrap" style="width:100px;">
    <input type="file" name="uploadTowedAccredit" id="uploadTowedAccredit" class="filetext"/>
  </p>
  <span id="uploadTowedAccreditLinkTip" class="warn-tips"><em></em>请上传附件,最多上传${towedAccreditPicMax} 张</span>
  <p id="towedAccreditp" class="up-img-list clearfix"></p>
</li>
Copy after login

// 上传拖机授权委托书
function uploadTowedAccreditInit(){
   $("#uploadTowedAccredit").uploadify({
    &#39;hideButton&#39;:&#39;true&#39;,
    &#39;preventCaching&#39; : &#39;true&#39;,
    &#39;checkExisting&#39;:&#39;true&#39;,
    &#39;swf&#39;: SWF, 
    &#39;uploader&#39;:uploadImg,
    &#39;debug&#39;:false,
    &#39;multi&#39;: true,
    &#39;method&#39;: &#39;post&#39;,
    &#39;preventCaching&#39; : true,
    &#39;removeCompleted&#39; : true,
    &#39;removeTimeout&#39; : 10,
    &#39;requeueErrors&#39; : true,
    &#39;successTimeout&#39; : 30,
    &#39;uploadLimit&#39; : ${towedAccreditPicMax},
     
    &#39;fileObjName&#39; : &#39;Filedata&#39;,
    //单张图片最大限制
    &#39;fileSizeLimit&#39; : &#39;1024KB&#39;,
    &#39;fileTypeDesc&#39; : &#39;Image Files&#39;,
    //仅限上传jpg格式图片
    &#39;fileTypeExts&#39; : &#39;*.jpg;*.png&#39;,
    &#39;height&#39;: 24,
    &#39;width&#39;:73,
    &#39;buttonText&#39; : &#39;上传附件&#39;,
    &#39;auto&#39;: true,
    &#39;buttonClass&#39;:&#39;uploada btn-fff-24&#39;,
   
    &#39;onSWFReady&#39; : function() {
    },
     
    &#39;onInit&#39;:function(){
      // $("#file_upload-button").css("width","100");
     },
         
    //选择图片完成
    &#39;onSelect&#39; : function() {
 
    },
     
    //取消上传
    &#39;onCancel&#39; : function(file) {
    },
    &#39;onCheck&#39;: function(event,data,key) {
    },
    //开始上传
    &#39;onUploadStart&#39; : function(file) {
      $(&#39;.uploadify-queue&#39;).html(&#39;&#39;);
    },
     
    //上传过程中
    &#39;onUploadProgress&#39; : function(file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {
      $(&#39;.uploadify-queue&#39;).html(&#39;&#39;);
      $("#uploadTowedAccreditLinkTip").html(&#39;<em></em>上传中...&#39;);
    },
     
    //上传完成
    &#39;onUploadComplete&#39; : function(file) {
        $(&#39;.uploadify-queue&#39;).html(&#39;&#39;);
        $("#uploadTowedAccreditLinkTip").html(&#39;<em></em>上传成功,待提交&#39;);
    },
     
    //上传成功
    &#39;onUploadSuccess&#39; : function(file, data, response) {
      var obj = eval(&#39;(&#39; + data + &#39;)&#39;);
        var result=obj.result;
        if(result=="true"){
          var filename=obj.filename;
          $(&#39;.uploadify-queue&#39;).html(&#39;&#39;);
          $(&#39;#towedAccreditp&#39;).append("<p class=&#39;img-wrap&#39;><img width=&#39;112&#39; height=&#39;84&#39; alt=&#39;&#39; src=&#39;"+filename+"&#39;><p class=&#39;mask&#39;><em></em><span></span></p></p>");
        }
    },
     
    //上传失败 //附件格式不正确,请上传JPG、BMP、PNG格式文件,大小不超过3MB
    &#39;onUploadError&#39; : function(file, errorCode, errorMsg, errorString) {
      switch(errorCode) {
        case -100:
          alert("上传的文件数量已经超出系统限制的"+$(&#39;#uploadTowedAccredit&#39;).uploadify(&#39;settings&#39;,&#39;queueSizeLimit&#39;)+"个文件!");
          break;
        case -110:
          alert("文件 ["+file.name+"] 大小超出系统限制的"+$(&#39;#uploadTowedAccredit&#39;).uploadify(&#39;settings&#39;,&#39;fileSizeLimit&#39;)+"大小!");
          break;
        case -120:
          alert("文件 ["+file.name+"] 大小异常!");
          break;
        case -130:
          alert("文件 ["+file.name+"] 类型不正确!");
          break;
      }
    },
    //上传失败 //附件格式不正确,请上传JPG、BMP、PNG格式文件,大小不超过3MB
    &#39;onSelectError&#39; : function(file, errorCode, errorMsg) { 
      var msgText = "上传失败\n"; 
      switch (errorCode) { 
        case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED: 
          var towedAccreditpLen = $("#towedAccreditp").children().length;
          msgText += "每次最多上传 " + $(&#39;#uploadTowedAccredit&#39;).uploadify(&#39;settings&#39;,&#39;uploadLimit&#39;) + "个文件"; 
          break; 
        case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT: 
          msgText += "文件大小超过限制( " + $(&#39;#uploadTowedAccredit&#39;).uploadify(&#39;settings&#39;,&#39;fileSizeLimit&#39;) + " )"; 
          break; 
        case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE: 
          msgText += "文件大小为0"; 
          break; 
        case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE: 
          msgText += "文件格式不正确,仅限 " + $(&#39;#uploadTowedAccredit&#39;).uploadify(&#39;settings&#39;,&#39;fileTypeExts&#39;); 
          break; 
        default: 
          msgText += "错误代码:" + errorCode + "\n" + errorMsg; 
      }
      alert(msgText);
    }
  });
   
  //判断用户是否有安装flash
 var obj = $("#uploadTowedAccredit").children().eq(0);
 if(obj.attr(&#39;type&#39;)!= "application/x-shockwave-flash"){
    alert(&#39;系统检测到您的浏览器没有安装flash插件,为了你能够正常上传图片,建议你安装flash&#39;);
    return;
  }
   
  $("#uploadTowedAccredit").css("float","left");
};
Copy after login

In addition, I attach jquery uploadify multi-file upload for everyone

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<title>php jquery uploadify多文件上传</title>
<link href=”css/default.css” rel=”stylesheet” type=”text/css” />
<link href=”css/uploadify.css” rel=”stylesheet” type=”text/css” />
<script type=”text/javascript” src=”js/jquery-1.3.2.min.js”></script>
<script type=”text/javascript” src=”js/swfobject.js”></script>
<script type=”text/javascript” src=”js/jquery.uploadify.v2.1.0.min.js”></script>
<script type=”text/javascript”>
$(document).ready(function() {
$(“#fileInput2″).uploadify({
‘uploader&#39;: ‘js/uploadify.swf&#39;,//所需要的flash文件
‘cancelImg&#39;: ‘cancel.png&#39;,//单个取消上传的图片
&#39;script&#39;: ‘js/uploadify.php&#39;,//实现上传的程序
‘folder&#39;: ‘uploads&#39;,//服务端的上传目录
//&#39;auto&#39;: true,//自动上传
‘multi&#39;: true,//是否多文件上传
//&#39;checkScript&#39;: ‘js/check.php&#39;,//验证 ,服务端的
‘displayData&#39;: &#39;speed&#39;,//进度条的显示方式
//&#39;fileDesc&#39;: ‘Image(*.jpg;*.gif;*.png)&#39;,//对话框的文件类型描述
//&#39;fileExt&#39;: ‘*.jpg;*.jpeg;*.gif;*.png&#39;,//可上传的文件类型
//&#39;sizeLimit&#39;: 999999 ,//限制上传文件的大小
//&#39;simUploadLimit&#39; :3, //并发上传数据
//&#39;queueSizeLimit&#39; :5, //可上传的文件个数
//&#39;buttonText&#39; :&#39;文件上传&#39;,//通过文字替换钮扣上的文字
‘buttonImg&#39;: ‘css/images/browseBtn.png&#39;,//替换上传钮扣
‘width&#39;: 80,//buttonImg的大小
‘height&#39;: 24,//
‘rollover&#39;: true,//button是否变换
onComplete: function (evt, queueID, fileObj, response, data) {
//alert(“Successfully uploaded: “+fileObj.filePath);
//alert(response);
getResult(response);//获得上传的文件路径
}
//onError: function(errorObj) {
// alert(errorObj.info+” “+errorObj.type);
//}
});
});
</script>
<script type=”text/javascript”>
function getResult(content){
//通过上传的图片来动态生成text来保存路径
var board = document.getElementById(“pTxt”);
board.style.display=””;
var newInput = document.createElement(“input”);
newInput.type = “text”;
newInput.size = “45″;
newInput.name=”myFilePath[]“;
var obj = board.appendChild(newInput);
var br= document.createElement(“br”);
board.appendChild(br);
obj.value=content;
}
</script>
</head>
<body>
<fieldset style=”border: 1px solid #CDCDCD; padding: 8px; padding-bottom:0px; margin: 8px 0″>
<legend> <strong> 多文件上传</strong></legend>
<p>
<input id=”fileInput2″ name=”fileInput2″ type=”file” />
<input type=”button” value=”确定上传” onclick=”javascript:$(‘#fileInput2′).uploadifyUpload();”>  
||  <a href=”javascript:$(‘#fileInput2′).uploadifyClearQueue();”>清除上传列表</a></p>
<p></p>
</fieldset>
<FORM name=”form2″ METHOD=POST ACTION=”db.php”>
 <p id=”pTxt” style=”display:none”><span style=”color:red”><strong>已经上传的图片有:</strong></span& gt;<br></p><br>
<INPUT TYPE=”submit” value=”提 交”>
</FORM>
</body>
</html>
Copy after login

The above is the entire content of this article, I hope it will be useful for everyone's learning For help, please pay attention to the PHP Chinese website for more related content!

Related recommendations:

Analysis of jQuery file upload control Uploadify

How to use FlatList in ReactNative

The above is the detailed content of Implementation of limiting the number of uploadify uploads in js. For more information, please follow other related articles on the PHP Chinese website!

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 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months 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)

How do I create and publish my own JavaScript libraries? How do I create and publish my own JavaScript libraries? Mar 18, 2025 pm 03:12 PM

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

How do I optimize JavaScript code for performance in the browser? How do I optimize JavaScript code for performance in the browser? Mar 18, 2025 pm 03:14 PM

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

How do I debug JavaScript code effectively using browser developer tools? How do I debug JavaScript code effectively using browser developer tools? Mar 18, 2025 pm 03:16 PM

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

How do I use source maps to debug minified JavaScript code? How do I use source maps to debug minified JavaScript code? Mar 18, 2025 pm 03:17 PM

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts Getting Started With Chart.js: Pie, Doughnut, and Bubble Charts Mar 15, 2025 am 09:19 AM

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion

TypeScript for Beginners, Part 2: Basic Data Types TypeScript for Beginners, Part 2: Basic Data Types Mar 19, 2025 am 09:10 AM

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript

See all articles