当前位置:首页 > PHP教程 > php上传下载 > 列表

php+jQuery.uploadify实现文件上传教程

发布:smiling 来源: PHP粉丝网  添加日期:2021-05-04 18:53:23 浏览: 评论:0 

这篇文章主要介绍了php+jQuery.uploadify实现文件上传教程,需要的朋友可以参考下

这两天用上传的控件,PHP+Jquery今天先介绍这个uploadify,嗯,我今天下载因为我英文不是很好所以我就在网上找的使用教程,我发现好多用不了,我那个去,你看官方文档才知道很多API已经不是以前的API了。今天总结一下给大家,给大家一个提醒最多还是要看官方的http://www.uploadify.com/documentation/!

简单举例一下使用然后我都加上注释给大家,方便大家阅读和使用下载官方的之后直接使用就OK了,当然你需要什么在直接修改就可以了!代码如下:

  1. <!DOCTYPE HTML> 
  2. <html> 
  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.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. </style> 
  14. </head> 
  15. <body> 
  16.  <h1>Uploadify讲解由widuu提供</h1> 
  17.  <form> 
  18.   <div id="queue"></div> 
  19.   <input id="file_upload" name="file_upload" type="file" multiple="true"> 
  20.  </form> 
  21.  <script type="text/javascript"> 
  22.   <?php $timetimestamp = time();?> 
  23.   $(function() { 
  24.    $('#file_upload').uploadify({ 
  25.      
  26.     //上传文件时post的的数据 
  27.     'formData'     : { 
  28.      'timestamp' : '<?php echo $timestamp;?>', 
  29.      'token'     : '<?php echo md5('unique_salt' . $timestamp);?>', 
  30.      'id'  : 1 
  31.     }, 
  32.     'swf'      : '/uploadify/uploadify.swf', 
  33.     'uploader' : 'http://localhost/uploadify/uploadify.php', 
  34.     'onInit'   : function(index){ 
  35.      alert('队列ID:'+index.settings.queueID); 
  36.     }, 
  37.     'method'   : 'post', //设置上传的方法get 和 post 
  38.     //'auto'    : false, //是否自动上传 false关闭自动上传 true 选中文件后自动上传 
  39.     //'buttonClass' : 'myclass', //自定义按钮的样式 
  40.     //'buttonImage' : '按钮图片', 
  41.     'buttonText'  : '选择文件', //按钮显示的字迹 
  42.     //'fileObjName' : 'mytest'  //后台接收的时候就是$_FILES['mytest'] 
  43.     'checkExisting' : '/uploadify/check-exists.php', //检查文件是否已经存在 返回0或者1 
  44.     'fileSizeLimit' : '100KB', //上传文件大小的限制 
  45.     'fileTypeDesc'  : '你需要一些文件',//可选择的文件的描述 
  46.     'fileTypeExts'  : '*.gif; *.jpg; *.png', //文件的允许上传的类型 
  47.      
  48.     //上传的时候发生的事件 
  49.     'onUploadStart' : function(file){ 
  50.       alert('开始上传了');       }, 
  51.     'uploadLimit'   : 5, //设置最大上传文件的数量 
  52.     /* 
  53.     'onUploadComplete' : function(result){ 
  54.         for (var i in result.post){ 
  55.          alert(i+':::'+result[i]); 
  56.         } 
  57.        }, 
  58.     */ 
  59.     //文件上传成功的时候 
  60.     'onUploadSuccess' : function(file, data, response) { 
  61.      alert(data); 
  62.      }, 
  63.      // 
  64.        'onUploadError' : function(file, errorCode, errorMsg, errorString) { 
  65.      alert(file.name + '上传失败原因:' + errorString); 
  66.      }, 
  67.      'itemTemplate' : '追加到每个上传节点的html', 
  68.      'height'  : 30, //设置高度 button 
  69.      'width'  : 30, //设置宽度 
  70.      'onDisable' : function(){ 
  71.       alert('您禁止上传'); 
  72.      }, 
  73.      'onEnable'  : function(){ 
  74.       alert('您可以继续上传了'); 
  75.      }, 
  76.      //当文件选中的时候 
  77.      'onSelect'  : function(file){ 
  78.       alert(file.name+"已经添加到队列"); 
  79.      } 
  80.    }); 
  81.   }); 
  82.    
  83.  //一些常用的事件 
  84.  //$('#file_upload').uploadify('upload','*');    //用javascript 上传的方法 
  85.  //$('#file_upload').uploadify('stop','*');      //用javascript 停止上传的方法 
  86.  //$('#file_upload').uploadify('disable','*');   //用javascript 禁止上传的方法 
  87.  //$('#file_upload').uploadify('settings','buttonText',"设置上传按钮");   //设置一些属性 
  88.  //更多的请到官方网站www.uploadify.com/documentation/看讲解谢谢 
  89.  </script> 
  90. <?php 
  91. /* 
  92.  *检查文件是否存在的check-exists.php 
  93.  */ 
  94. /* 
  95. $targetFolder = '/uploads'; 
  96. if (file_exists($_SERVER['DOCUMENT_ROOT'] . $targetFolder . '/' . $_POST['filename'])) { 
  97.  echo 1; 
  98. } else { 
  99.  echo 0; 
  100. } 
  101. */ 
  102. ?> 
  103. </body> 
  104. </html> 

代码注释里都做了详细解释了,我这里就不多废话了,如果还是有疑问,那就联系我吧。

Tags: php+jQuery uploadify

分享到: