uploadify上传文件

来源:互联网 发布:淘宝海参老板神对话 编辑:程序博客网 时间:2024/05/16 11:50

发现网上很多人写的都好像是旧的方法,好像已经过时了……找了很久

在Change Log.txt中看的见版本

这个是我的v3.2.1- Updated uploadify.swf with security updates from secure swfupload.

自己写了一个,又找了别人的一个,贴上两个文件

这个是我自己写的,实现了 单个文件和多文件上传的效果

Html代码  收藏代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  5. <title>uploadify多文件上传</title>  
  6.   
  7. <script type="text/javascript" src="../js/jquery-1.7.2.js" ></script>  
  8. <script type="text/javascript" src="uploadify/scripts/jquery.uploadify.js" ></script>  
  9.   
  10. <script type="text/javascript">  
  11.     $(function(){  
  12.         $("#testFileInput").uploadify({  
  13.             swf:'uploadify/scripts/uploadify.swf',  
  14.             uploader:'../UploadUtil',  
  15.             formData:{PHPSESSID:'xxx', ajax:1},  
  16.             buttonText:'请选择文件',  
  17.             fileSizeLimit:'200KB',  
  18.             fileTypeDesc:'*.jpg;*.jpeg;*.gif;*.png;',  
  19.             fileTypeExts:'*.jpg;*.jpeg;*.gif;*.png;',  
  20.             auto:true,  
  21.             multi:true  
  22.         });  
  23.         $("#testFileInput2").uploadify({  
  24.             swf:'uploadify/scripts/uploadify.swf',  
  25.             uploader:'../UploadUtil',  
  26.             queueID:'fileQueue',  
  27.             buttonImage:'uploadify/img/add.jpg',  
  28.             buttonClass:'my-uploadify-button',  
  29.             cancelImg: 'uploadify/img/cancel.jpg',  
  30.             width:102,  
  31.             auto:false,  
  32.             multi:true  
  33.         });  
  34.     });  
  35. </script>  
  36.   
  37. <link rel="stylesheet" type="text/css" href="uploadify/css/uploadify.css"/>  
  38.   
  39. <style type="text/css" media="screen">  
  40. .my-uploadify-button {  
  41.     background:none;  
  42.     border: none;  
  43.     text-shadow: none;  
  44.     border-radius:0;  
  45. }  
  46.   
  47. .uploadify:hover .my-uploadify-button {  
  48.     background:none;  
  49.     border: none;  
  50. }  
  51.   
  52. .fileQueue {  
  53.     width: 400px;  
  54.     height: 150px;  
  55.     overflow: auto;  
  56.     border: 1px solid #E5E5E5;  
  57.     margin-bottom: 10px;  
  58. }  
  59. </style>  
  60.   
  61. </head>  
  62. <body>  
  63. <h2>uploadify多文件上传</h2>  
  64.         <input id="testFileInput" type="file" name="image" />  
  65.   
  66.     <div class="divider"></div>  
  67.   
  68.     <input id="testFileInput2" type="file" name="image2" />  
  69.       
  70.     <div id="fileQueue" class="fileQueue"></div>  
  71.       
  72.     <input type="image" src="uploadify/img/upload.jpg" onclick="$('#testFileInput2').uploadify('upload', '*');"/>  
  73.     <input type="image" src="uploadify/img/cancel.jpg" onclick="$('#testFileInput2').uploadify('cancel', '*');"/>  
  74. </body>  
  75. </html>  

 这个是别人写的,具体解释了参数的意义和使用方法,呃,已经很完整了,也可以自己再上网找找

 

Html代码  收藏代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  5. <title>uploadify 多文件上传例子</title>  
  6. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>  
  7. <script src="jquery.uploadify-3.1.min.js" type="text/javascript"></script>  
  8. <link rel="stylesheet" type="text/css" href="uploadify.css">  
  9. <style type="text/css">  
  10. body {  
  11.     font: 13px Arial, Helvetica, Sans-serif;  
  12. }  
  13. .haha{  
  14.     color:#FFFFFF;  
  15. }  
  16. #queue {  
  17.     background-color: #FFF;  
  18.     border-radius: 3px;  
  19.     box-shadow: 0 1px 3px rgba(0,0,0,0.25);  
  20.     height: 103px;  
  21.     margin-bottom: 10px;  
  22.     overflow: auto;  
  23.     padding: 5px 10px;  
  24.     width: 300px;  
  25. }  
  26. </style>  
  27. </head>  
  28.   
  29.   
  30. <body>  
  31.     <h1>Uploadify Demo</h1>  
  32.     <form>  
  33.         <div id="queue"></div>  
  34.         <input id="file_upload" name="file_upload" type="file" multiple="true">  
  35.     </form>  
  36.       
  37.     <script type="text/javascript">  
  38.         $(function() {  
  39.             $('#file_upload').uploadify({  
  40.                 'debug'         : false,  
  41.                 'auto'          : true,             //是否自动上传,  
  42.                 'buttonClass'   : 'haha',           //按钮辅助class  
  43.                 'buttonText'    : '上传图片',       //按钮文字  
  44.                 'height'        : 30,               //按钮高度  
  45.                 'width'         : 100,              //按钮宽度  
  46.                 //'checkExisting' : 'check-exists.php',//是否检测图片存在,不检测:false  
  47.                 'fileObjName'   : 'files',           //默认 Filedata, $_FILES控件名称  
  48.                 'fileSizeLimit' : '1024KB',          //文件大小限制 0为无限制 默认KB  
  49.                 'fileTypeDesc'  : 'All Files',       //图片选择描述  
  50.                 'fileTypeExts'  : '*.gif; *.jpg; *.png',//文件后缀限制 默认:'*.*'  
  51.                 'formData'      : {'someKey' : 'someValue', 'someOtherKey' : 1},//传输数据JSON格式  
  52.                 //'overrideEvents': ['onUploadProgress'],  // The progress will not be updated  
  53.                 //'progressData' : 'speed',             //默认percentage 进度显示方式  
  54.                 'queueID'       : 'queue',              //默认队列ID  
  55.                 'queueSizeLimit': 20,                   //一个队列上传文件数限制  
  56.                 'removeCompleted' : true,               //完成时是否清除队列 默认true  
  57.                 'removeTimeout'   : 3,                  //完成时清除队列显示秒数,默认3秒  
  58.                 'requeueErrors'   : false,              //队列上传出错,是否继续回滚队列  
  59.                 'successTimeout'  : 5,                  //上传超时  
  60.                 'uploadLimit'     : 99,                 //允许上传的最多张数  
  61.                 'swf'  : 'uploadify.swf', //swfUpload  
  62.                 'uploader': 'uploadify.php', //服务器端脚本  
  63.   
  64.   
  65.                 //修改formData数据  
  66.                 'onUploadStart' : function(file) {  
  67.                     //$("#file_upload").uploadify("settings", "someOtherKey", 2);  
  68.                 },  
  69.                 //删除时触发  
  70.                 'onCancel' : function(file) {  
  71.                     //alert('The file ' + file.name + '--' + file.size + ' was cancelled.');  
  72.                 },  
  73.                 //清除队列  
  74.                 'onClearQueue' : function(queueItemCount) {  
  75.                     //alert(queueItemCount + ' file(s) were removed from the queue');  
  76.                 },  
  77.                 //调用destroy是触发  
  78.                 'onDestroy' : function() {  
  79.                     alert('我被销毁了');  
  80.                 },  
  81.                 //每次初始化一个队列是触发  
  82.                 'onInit' : function(instance){  
  83.                     //alert('The queue ID is ' + instance.settings.queueID);  
  84.                 },  
  85.                 //上传成功  
  86.                 'onUploadSuccess' : function(file, data, response) {  
  87.                     //alert(file.name + ' | ' + response + ':' + data);  
  88.                 },  
  89.                 //上传错误  
  90.                 'onUploadError' : function(file, errorCode, errorMsg, errorString) {  
  91.                     //alert('The file ' + file.name + ' could not be uploaded: ' + errorString);  
  92.                 },  
  93.                 //上传汇总  
  94.                 'onUploadProgress' : function(file, bytesUploaded, bytesTotal, totalBytesUploaded, totalBytesTotal) {  
  95.                     $('#progress').html(totalBytesUploaded + ' bytes uploaded of ' + totalBytesTotal + ' bytes.');  
  96.                 },  
  97.                 //上传完成  
  98.                 'onUploadComplete' : function(file) {  
  99.                     //alert('The file ' + file.name + ' finished processing.');  
  100.                 },  
  101.                
  102.             });  
  103.         });  
  104.   
  105.   
  106.         //变换按钮  
  107.         function changeBtnText() {  
  108.             $('#file_upload').uploadify('settings','buttonText','继续上传');  
  109.         }  
  110.   
  111.   
  112.         //返回按钮  
  113.         function returnBtnText() {  
  114.             alert('The button says ' + $('#file_upload').uploadify('settings','buttonText'));  
  115.         }  
  116.     </script>  
  117.     <h4>操作:</h4>   
  118.     <a href="javascript:$('#file_upload').uploadify('upload', '*');">开始上传</a> &nbsp;|&nbsp;  
  119.     <a href="javascript:$('#file_upload').uploadify('cancel', '*');">清除队列</a> &nbsp;|&nbsp;  
  120.     <a href="javascript:$('#file_upload').uploadify('destroy');">销毁上传</a> &nbsp;|&nbsp;  
  121.     <a href="javascript:$('#file_upload').uploadify('disable', true);">禁用上传</a> &nbsp;|&nbsp;  
  122.     <a href="javascript:$('#file_upload').uploadify('disable', false);">激活上传</a> &nbsp;|&nbsp;  
  123.     <a href="javascript:$('#file_upload').uploadify('stop');">停止上传</a> &nbsp;|&nbsp;  
  124.     <a href="javascript:changeBtnText();">变换按钮</a> &nbsp;|&nbsp;  
  125.     <h4>大小:</h4>  
  126.     <div id='progress'></div>   
  127. </body>  
  128. </html>  

 

0 0
原创粉丝点击