index.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. exit;
  3. require_once(dirname(__FILE__).'/../../inc/config.inc.php');
  4. /*
  5. **************************
  6. (C)2010-2013 phpMyWind.com
  7. update: 2012-9-15 12:14:40
  8. person: Feng
  9. **************************
  10. */
  11. //初始化参数
  12. $size = isset($size) ? $size : '';
  13. $num = isset($num) ? $num : '';
  14. $input = isset($input) ? $input : '';
  15. $area = isset($area) ? $area : '';
  16. $frame = isset($frame) ? $frame : '';
  17. $title = isset($title) ? $title : '';
  18. $type = isset($type) ? $type : '';
  19. //获取上传文件类型
  20. function GetUpType($type='')
  21. {
  22. global $cfg_upload_img_type,
  23. $cfg_upload_soft_type,
  24. $cfg_upload_media_type;
  25. if($type == 'image')
  26. {
  27. $uptype = explode('|',$cfg_upload_img_type);
  28. $upstr = '';
  29. foreach($uptype as $v)
  30. {
  31. if(!empty($v))
  32. {
  33. $upstr .= '*.'.$v.';';
  34. }
  35. }
  36. return $upstr;
  37. }
  38. else if($type == 'soft')
  39. {
  40. $uptype = explode('|',$cfg_upload_soft_type);
  41. $upstr = '';
  42. foreach($uptype as $v)
  43. {
  44. if(!empty($v))
  45. {
  46. $upstr .= '*.'.$v.';';
  47. }
  48. }
  49. return $upstr;
  50. }
  51. else if($type == 'media')
  52. {
  53. $uptype = explode('|',$cfg_upload_media_type);
  54. $upstr = '';
  55. foreach($uptype as $v)
  56. {
  57. if(!empty($v))
  58. {
  59. $upstr .= '*.'.$v.';';
  60. }
  61. }
  62. return $upstr;
  63. }
  64. else if($type == 'all')
  65. {
  66. $alltype = $cfg_upload_img_type.'|'.$cfg_upload_soft_type.'|'.$cfg_upload_media_type;
  67. $uptype = explode('|',$alltype);
  68. $upstr = '';
  69. foreach($uptype as $v)
  70. {
  71. if(!empty($v))
  72. {
  73. $upstr .= '*.'.$v.';';
  74. }
  75. }
  76. return $upstr;
  77. }
  78. else
  79. {
  80. return $type;
  81. }
  82. }
  83. //获取上传文件描述
  84. function GetUpDesc($desc)
  85. {
  86. if($desc == 'image') return '图像类型:';
  87. else if($desc == 'soft') return '软件类型:';
  88. else if($desc == 'media') return '媒体类型:';
  89. else if($desc == 'all') return '所有类型:';
  90. else return $desc;
  91. }
  92. //引入水印配置文件
  93. require_once(PHPMYWIND_DATA.'/watermark/watermark.inc.php');
  94. ?>
  95. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  96. <html xmlns="http://www.w3.org/1999/xhtml">
  97. <head>
  98. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  99. <title>Uploadify</title>
  100. <link rel="stylesheet" type="text/css" href="uploadify.css">
  101. </head>
  102. <body>
  103. <script type="text/javascript" src="jquery.min.js"></script>
  104. <script type="text/javascript" src="jquery.uploadify.js"></script>
  105. <script type="text/javascript">
  106. //设置上传后样式
  107. function SetImgContent(data)
  108. {
  109. if(data == '')
  110. {
  111. alert('您上传的文件可能超过php.ini设置的最大内容提交大小[<?php echo get_cfg_var('post_max_size'); ?>]!');
  112. return;
  113. }
  114. else
  115. {
  116. var resjson = data.split(",");
  117. if(resjson[0] == 0)
  118. {
  119. alert(resjson[1]);
  120. return;
  121. }
  122. else
  123. {
  124. var sLi = "";
  125. sLi += '<li class="img">';
  126. sLi += '<img src="../../../' + resjson[2] + '" width="100" height="100" onerror="this.src=\'nopic.png\'">';
  127. sLi += '<input type="hidden" name="fileurl_tmp[]" value="' + resjson[2] + '">';
  128. sLi += '<a href="javascript:void(0);">删除</a>';
  129. sLi += '</li>';
  130. return sLi;
  131. }
  132. }
  133. }
  134. //删除上传元素DOM并清除目录文件
  135. function SetUploadFile()
  136. {
  137. $("ul li").each(function(l_i){
  138. $(this).attr("id", "li_" + l_i);
  139. })
  140. $("ul li a").each(function(a_i){
  141. $(this).attr("rel", "li_" + a_i);
  142. }).click(function(){
  143. $.get(
  144. 'uploadify.php',
  145. {action:"del", filename:$(this).prev().val()},
  146. function(){}
  147. );
  148. $("#" + this.rel).remove();
  149. })
  150. }
  151. $(function() {
  152. $('#uploadify').uploadify({
  153. 'formData' : {
  154. 'sessionid' : '<?php echo session_id(); ?>',
  155. 'timestamp' : '<?php echo time();?>',
  156. 'token' : '<?php echo md5('unique_salt'.time()); ?>'
  157. },
  158. 'queueSizeLimit' : '<?php echo @$num; ?>',
  159. 'fileSizeLimit' : '<?php echo @$size; ?>',
  160. 'fileTypeExts' : '<?php echo @GetUpType($type); ?>',
  161. 'fileTypeDesc' : '<?php echo @GetUpDesc($desc); ?>',
  162. 'buttonImage' : 'select.png',
  163. 'queueID' : 'fileQueue',
  164. 'onUploadStart' : function(file){
  165. $('#uploadify').uploadify('settings', 'formData', {'iswatermark':$("#iswatermark").attr("checked")});
  166. },
  167. 'onUploadSuccess' : function(file, data, response){
  168. $(".fileWarp ul").append(SetImgContent(data));
  169. SetUploadFile();
  170. }
  171. });
  172. //移动代码开始
  173. var _move = false;
  174. var ObjT = ".MainTit";
  175. var ObjW = ".Wrap";
  176. //鼠标离控件左上角的相对位置
  177. var _x,_y,_top,_left;
  178. //初始化窗口位置
  179. _top = parseInt($(window.parent.window).height()/2)-208 + $(window.parent.document).scrollTop();
  180. _left = parseInt($(window.parent.window).width()/2)-245;
  181. $(ObjW).css({"top":_top,"left":_left});
  182. //浏览器窗口发生变化时窗口位置
  183. $(window).resize(function(){
  184. _top = parseInt($(window.parent.window).height()/2)-208 + $(window.parent.document).scrollTop();
  185. _left = parseInt($(window.parent.window).width()/2)-245;
  186. $(ObjW).css({"top":_top,"left":_left});
  187. });
  188. //鼠标按下时允许进行移动操作
  189. $(ObjT).mousedown(function(e){
  190. _move = true;
  191. _x = e.pageX - parseInt($(ObjW).css("left"));
  192. _y = e.pageY - parseInt($(ObjW).css("top"));
  193. });
  194. $(document).mousemove(function(e){
  195. if(_move){
  196. //移动时根据鼠标位置计算控件左上角的绝对位置
  197. var x = e.pageX - _x;
  198. var y = e.pageY - _y;
  199. //控件新位置
  200. $(ObjW).css({top:y,left:x});
  201. }
  202. }).mouseup(function(){
  203. _move = false;
  204. });
  205. /*点击保存按钮时
  206. *判断允许上传数,检测是单一文件上传还是组文件上传
  207. *如果是单一文件,上传结束后将地址存入$input元素
  208. *如果是组文件上传,则创建input样式,添加到$input后面
  209. *隐藏父框架,清空列队,移除已上传文件样式*/
  210. $("#SaveBtn").click(function(){
  211. if(<?php echo $num ;?> > 1)
  212. {
  213. var fileurl_tmp = "";
  214. $("input[name^='fileurl_tmp']").each(function(){
  215. fileurl_tmp += '<li rel="'+ this.value +'"><input type="text" name="<?php echo $input; ?>[]" value="'+ this.value +'" /><a href="javascript:void(0);" onclick="ClearPicArr(\''+ this.value +'\')">删除</a></li>';
  216. });
  217. $(window.parent.document).find("#<?php echo $area ;?>").append(fileurl_tmp);
  218. }
  219. else
  220. {
  221. $(window.parent.document).find("#<?php echo $input ;?>").val($("input[name^='fileurl_tmp']").val());
  222. }
  223. $(window.parent.document).find("#<?php echo $frame ;?>").remove();
  224. });
  225. /*点击关闭或取消按钮时
  226. **隐藏父框架,清空列队,移除已上传文件样式*/
  227. $(".Close, #CancelBtn").click(function(){
  228. $("#<?php echo $frame ;?>", window.parent.document).remove();
  229. //$('#uploadify').uploadifyClearQueue();
  230. //$(".fileWarp ul li").remove();
  231. });
  232. });
  233. </script>
  234. <div class="W">
  235. <div class="Bg">
  236. </div>
  237. <div class="Wrap">
  238. <div class="Title">
  239. <h3 class="MainTit"><?php echo $title; ?></h3>
  240. <a href="javascript:;" title="关闭" class="Close"> </a>
  241. </div>
  242. <div class="Cont">
  243. <p class="Note">最多上传<strong><?php echo $num; ?></strong>个附件,单文件最大<strong><?php echo GetRealSize($size); ?></strong>,类型<strong><?php echo GetUpType($type); ?></strong></p>
  244. <div class="flashWrap">
  245. <input name="uploadify" id="uploadify" type="file" multiple="true" />
  246. <span><input type="checkbox" name="iswatermark" id="iswatermark" <?php if($cfg_markswitch=='Y') echo 'checked="checked"' ?> /><label>是否添加水印</label></span>
  247. </div>
  248. <div class="fileWarp">
  249. <fieldset>
  250. <legend>列表</legend>
  251. <ul>
  252. </ul>
  253. <div id="fileQueue">
  254. </div>
  255. </fieldset>
  256. </div>
  257. <div class="btnBox">
  258. <button class="btn" id="SaveBtn">保存</button>
  259. &nbsp;
  260. <button class="btn" id="CancelBtn">取消</button>
  261. </div>
  262. </div>
  263. <!--[if IE 6]>
  264. <iframe frameborder="0" style="width:100%;height:100px;background-color:transparent;position:absolute;top:0;left:0;z-index:-1;"></iframe>
  265. <![endif]-->
  266. </div>
  267. </div>
  268. </body>
  269. </html>