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(); */ }); };
##
<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>
// 上传拖机授权委托书 function uploadTowedAccreditInit(){ $("#uploadTowedAccredit").uploadify({ 'hideButton':'true', 'preventCaching' : 'true', 'checkExisting':'true', 'swf': SWF, 'uploader':uploadImg, 'debug':false, 'multi': true, 'method': 'post', 'preventCaching' : true, 'removeCompleted' : true, 'removeTimeout' : 10, 'requeueErrors' : true, 'successTimeout' : 30, 'uploadLimit' : ${towedAccreditPicMax}, 'fileObjName' : 'Filedata', //单张图片最大限制 'fileSizeLimit' : '1024KB', 'fileTypeDesc' : 'Image Files', //仅限上传jpg格式图片 'fileTypeExts' : '*.jpg;*.png', 'height': 24, 'width':73, 'buttonText' : '上传附件', 'auto': true, 'buttonClass':'uploada btn-fff-24', 'onSWFReady' : function() { }, 'onInit':function(){ // $("#file_upload-button").css("width","100"); }, //选择图片完成 'onSelect' : function() { }, //取消上传 'onCancel' : function(file) { }, 'onCheck': function(event,data,key) { }, //开始上传 'onUploadStart' : function(file) { $('.uploadify-queue').html(''); }, //上传过程中 'onUploadProgress' : function(file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) { $('.uploadify-queue').html(''); $("#uploadTowedAccreditLinkTip").html('<em></em>上传中...'); }, //上传完成 'onUploadComplete' : function(file) { $('.uploadify-queue').html(''); $("#uploadTowedAccreditLinkTip").html('<em></em>上传成功,待提交'); }, //上传成功 'onUploadSuccess' : function(file, data, response) { var obj = eval('(' + data + ')'); var result=obj.result; if(result=="true"){ var filename=obj.filename; $('.uploadify-queue').html(''); $('#towedAccreditp').append("<p class='img-wrap'><img width='112' height='84' alt='' src='"+filename+"'><p class='mask'><em></em><span></span></p></p>"); } }, //上传失败 //附件格式不正确,请上传JPG、BMP、PNG格式文件,大小不超过3MB 'onUploadError' : function(file, errorCode, errorMsg, errorString) { switch(errorCode) { case -100: alert("上传的文件数量已经超出系统限制的"+$('#uploadTowedAccredit').uploadify('settings','queueSizeLimit')+"个文件!"); break; case -110: alert("文件 ["+file.name+"] 大小超出系统限制的"+$('#uploadTowedAccredit').uploadify('settings','fileSizeLimit')+"大小!"); break; case -120: alert("文件 ["+file.name+"] 大小异常!"); break; case -130: alert("文件 ["+file.name+"] 类型不正确!"); break; } }, //上传失败 //附件格式不正确,请上传JPG、BMP、PNG格式文件,大小不超过3MB 'onSelectError' : function(file, errorCode, errorMsg) { var msgText = "上传失败\n"; switch (errorCode) { case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED: var towedAccreditpLen = $("#towedAccreditp").children().length; msgText += "每次最多上传 " + $('#uploadTowedAccredit').uploadify('settings','uploadLimit') + "个文件"; break; case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT: msgText += "文件大小超过限制( " + $('#uploadTowedAccredit').uploadify('settings','fileSizeLimit') + " )"; break; case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE: msgText += "文件大小为0"; break; case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE: msgText += "文件格式不正确,仅限 " + $('#uploadTowedAccredit').uploadify('settings','fileTypeExts'); break; default: msgText += "错误代码:" + errorCode + "\n" + errorMsg; } alert(msgText); } }); //判断用户是否有安装flash var obj = $("#uploadTowedAccredit").children().eq(0); if(obj.attr('type')!= "application/x-shockwave-flash"){ alert('系统检测到您的浏览器没有安装flash插件,为了你能够正常上传图片,建议你安装flash'); return; } $("#uploadTowedAccredit").css("float","left"); };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': ‘js/uploadify.swf',//所需要的flash文件 ‘cancelImg': ‘cancel.png',//单个取消上传的图片 'script': ‘js/uploadify.php',//实现上传的程序 ‘folder': ‘uploads',//服务端的上传目录 //'auto': true,//自动上传 ‘multi': true,//是否多文件上传 //'checkScript': ‘js/check.php',//验证 ,服务端的 ‘displayData': 'speed',//进度条的显示方式 //'fileDesc': ‘Image(*.jpg;*.gif;*.png)',//对话框的文件类型描述 //'fileExt': ‘*.jpg;*.jpeg;*.gif;*.png',//可上传的文件类型 //'sizeLimit': 999999 ,//限制上传文件的大小 //'simUploadLimit' :3, //并发上传数据 //'queueSizeLimit' :5, //可上传的文件个数 //'buttonText' :'文件上传',//通过文字替换钮扣上的文字 ‘buttonImg': ‘css/images/browseBtn.png',//替换上传钮扣 ‘width': 80,//buttonImg的大小 ‘height': 24,// ‘rollover': 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>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!

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.