Upload.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\admin\controller;
  13. use app\model\upload\Upload as UploadModel;
  14. use app\model\upload\Config as ConfigModel;
  15. /**
  16. * 上传 控制器
  17. */
  18. class Upload extends BaseAdmin
  19. {
  20. /**
  21. * 上传配置
  22. */
  23. public function config()
  24. {
  25. $config_model = new ConfigModel();
  26. if (request()->isAjax()) {
  27. //基础上传
  28. $max_filesize = input("max_filesize", "10240");//允许上传大小
  29. $image_allow_ext = trim(input("image_allow_ext", ""));//图片允许扩展名
  30. $image_allow_mime = trim(input("image_allow_mime", ""));//图片允许Mime类型
  31. /*************************************************************************** 缩略图 *******************************************************************/
  32. $thumb_position = input("thumb_position", 'top-left');//自定义裁剪的位置。默认是 '中心' (相对于当前图像)top-left(默认)top top-right left center right bottom-left bottom bottom-right
  33. $thumb_big_width = input("thumb_big_width", 400);//缩略大图 宽
  34. $thumb_big_height = input("thumb_big_height", 400);//缩略大图 高
  35. $thumb_mid_width = input("thumb_mid_width", 200);//缩略中图 宽
  36. $thumb_mid_height = input("thumb_mid_height", 200);//缩略中图 高
  37. $thumb_small_width = input("thumb_small_width", 100);//缩略小图 宽
  38. $thumb_small_height = input("thumb_small_height", 100);//缩略小图 高
  39. /*************************************************************************** 水印 *******************************************************************/
  40. $is_watermark = input("is_watermark", 0);//是否开启水印
  41. $watermark_type = input("watermark_type", '1');//水印类型 1图片 2文字
  42. $watermark_source = input("watermark_source", '');//水印图片来源
  43. $watermark_position = input("watermark_position", 'top-left');//水印图片位置(相对于当前图像)top-left(默认)top top-right left center right bottom-left bottom bottom-right
  44. $watermark_x = input("watermark_x", 0);//水印图片横坐标偏移量
  45. $watermark_y = input("watermark_y", 0);//水印图片纵坐标偏移量
  46. $watermark_opacity = input("watermark_opacity", '0');//水印图片透明度
  47. $watermark_rotate = input("watermark_rotate", '0');//水印图片倾斜度
  48. $watermark_text = input("watermark_text", '');//水印文字
  49. $watermark_text_file = input("watermark_text_file", '');//水印文字 字体文件。设置True Type Font文件的路径,或者GD库内部字体之一的1到5之间的整数值。 默认值:1
  50. $watermark_text_size = input("watermark_text_size", '12');//水印文字 字体大小。字体大小仅在设置字体文件时可用,否则将被忽略。 默认值:12
  51. $watermark_text_color = input("watermark_text_color", '#000000');//水印文字 字体颜色
  52. $watermark_text_align = input("watermark_text_align", 'left');//水印文字水平对齐方式 水平对齐方式:left,right,center。默认left
  53. $watermark_text_valign = input("watermark_text_valign", 'bottom');//水印文字垂直对齐方式 垂直对齐方式:top,bottom,middle。默认bottom
  54. $watermark_text_angle = input("watermark_text_angle", '0');//文本旋转角度。文本将围绕垂直和水平对齐点逆时针旋转。 旋转仅在设置字体文件时可用,否则将被忽略
  55. $data = array(
  56. //上传相关配置
  57. "upload" => array(
  58. "max_filesize" => $max_filesize,//最大上传限制,
  59. "image_allow_ext" => $image_allow_ext,
  60. "image_allow_mime" => $image_allow_mime,
  61. ),
  62. //缩略图相关配置
  63. "thumb" => array(
  64. "thumb_position" => $thumb_position,
  65. "thumb_big_width" => $thumb_big_width,
  66. "thumb_big_height" => $thumb_big_height,
  67. "thumb_mid_width" => $thumb_mid_width,
  68. "thumb_mid_height" => $thumb_mid_height,
  69. "thumb_small_width" => $thumb_small_width,
  70. "thumb_small_height" => $thumb_small_height,
  71. ),
  72. //水印相关配置
  73. "water" => array(
  74. "is_watermark" => $is_watermark,
  75. "watermark_type" => $watermark_type,
  76. "watermark_source" => $watermark_source,
  77. "watermark_position" => $watermark_position,
  78. "watermark_x" => $watermark_x,
  79. "watermark_y" => $watermark_y,
  80. "watermark_opacity" => $watermark_opacity,
  81. "watermark_rotate" => $watermark_rotate,
  82. "watermark_text" => $watermark_text,
  83. "watermark_text_file" => $watermark_text_file,
  84. "watermark_text_size" => $watermark_text_size,
  85. "watermark_text_color" => $watermark_text_color,
  86. "watermark_text_align" => $watermark_text_align,
  87. "watermark_text_valign" => $watermark_text_valign,
  88. "watermark_text_angle" => $watermark_text_angle,
  89. ),
  90. );
  91. $this->addLog("修改上传配置");
  92. $result = $config_model->setUploadConfig($data);
  93. return $result;
  94. } else {
  95. $this->forthMenu();
  96. $config_result = $config_model->getUploadConfig();
  97. $config = $config_result["data"];
  98. $this->assign("config", $config);
  99. $position = array(
  100. "top-left" => "上左",
  101. "top" => "上中",
  102. "top-right" => "上右",
  103. "left" => "左",
  104. "center" => "中",
  105. "right" => "右",
  106. "bottom-left" => "下左",
  107. "bottom" => "下中",
  108. "bottom-right" => "下右",
  109. );//位置
  110. $this->assign("position", $position);
  111. return $this->fetch('upload/config');
  112. }
  113. }
  114. /**
  115. * 上传(不存入相册)
  116. * @return \app\model\upload\Ambigous|\multitype
  117. */
  118. public function upload()
  119. {
  120. $upload_model = new UploadModel();
  121. $thumb_type = input("thumb", "");
  122. $name = input("name", "");
  123. $param = array(
  124. "thumb_type" => "",
  125. "name" => "file"
  126. );
  127. $result = $upload_model->setPath("common/images/" . date("Ymd") . '/')->image($param);
  128. return $result;
  129. }
  130. /**
  131. * 上传 存入相册
  132. * @return \multitype
  133. */
  134. public function uploadToAlbum()
  135. {
  136. $upload_model = new UploadModel();
  137. $thumb_type = input("thumb", "");
  138. $name = input("name", "");
  139. $param = array(
  140. "thumb_type" => "",
  141. "name" => "file"
  142. );
  143. $result = $upload_model->setPath("common/images/" . date("Ymd") . '/')->imageToAlbum($param);
  144. return $result;
  145. }
  146. /**
  147. * 云上传方式
  148. */
  149. public function oss()
  150. {
  151. if (request()->isAjax()) {
  152. $config_model = new ConfigModel();
  153. $list = event('OssType', []);
  154. return $config_model->success($list);
  155. } else {
  156. $this->forthMenu();
  157. return $this->fetch("upload/oss");
  158. }
  159. }
  160. }