Snsalbum.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * 买家相册
  4. */
  5. namespace app\home\controller;
  6. use think\facade\Lang;
  7. use think\facade\Db;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class Snsalbum extends BaseMember {
  21. public function initialize() {
  22. parent::initialize();
  23. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/snsalbum.lang.php');
  24. }
  25. /**
  26. * 图片删除
  27. */
  28. public function album_pic_del() {
  29. $ids = input('param.id');
  30. if (empty($ids)) {
  31. ds_json_encode(10001, lang('album_parameter_error'));
  32. };
  33. if (!empty($ids) && is_array($ids)) {
  34. $id = $ids;
  35. } else {
  36. $id[] = intval($ids);
  37. }
  38. foreach ($id as $v) {
  39. $v = intval($v);
  40. if ($v <= 0)
  41. continue;
  42. $ap_info = Db::name('snsalbumpic')->where(array('ap_id' => $v, 'member_id' => session('member_id')))->find();
  43. if (empty($ap_info))
  44. continue;
  45. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_MALBUM . DIRECTORY_SEPARATOR . session('member_id') . DIRECTORY_SEPARATOR . $ap_info['ap_cover']);
  46. $res = Db::name('snsalbumpic')->delete($ap_info['ap_id']);
  47. }
  48. if ($res) {
  49. ds_json_encode(10000, lang('album_class_pic_del_succeed'));
  50. }
  51. }
  52. /**
  53. * 上传图片
  54. *
  55. * @param
  56. * @return
  57. */
  58. public function swfupload() {
  59. $member_id = session('member_id');
  60. $class_id = intval(input('param.category_id'));
  61. if ($member_id <= 0 && $class_id <= 0) {
  62. echo json_encode(array('state' => 'false', 'message' => lang('sns_upload_pic_fail'), 'origin_file_name' => $_FILES["file"]["name"]));
  63. exit;
  64. }
  65. /**
  66. * 上传图片
  67. */
  68. //上传文件保存路径
  69. if (!empty($_FILES['file']['name'])) {
  70. //设置特殊图片名称
  71. $file_name = $member_id . '_' . date('YmdHis') . rand(10000, 99999).'.png';
  72. $res = ds_upload_pic(ATTACH_MALBUM . DIRECTORY_SEPARATOR . $member_id, 'file', $file_name);
  73. if ($res['code']) {
  74. $img_path = $res['data']['file_name'];
  75. } else {
  76. $error = $res['msg'];
  77. $data['state'] = 'false';
  78. $data['message'] = $error;
  79. $data['origin_file_name'] = $_FILES['file']['name'];
  80. echo json_encode($data);
  81. exit;
  82. }
  83. } else {
  84. //未上传图片不做后面处理
  85. exit;
  86. }
  87. list($width, $height, $type, $attr) = getimagesize(ds_get_pic(ATTACH_MALBUM . DIRECTORY_SEPARATOR . $member_id, $img_path));
  88. $insert = array();
  89. $insert['ap_name'] = $img_path;
  90. $insert['ac_id'] = $class_id;
  91. $insert['ap_cover'] = $img_path;
  92. $insert['ap_size'] = intval($_FILES['file']['size']);
  93. $insert['ap_spec'] = $width . 'x' . $height;
  94. $insert['ap_uploadtime'] = TIMESTAMP;
  95. $insert['member_id'] = $member_id;
  96. $result = Db::name('snsalbumpic')->insertGetId($insert);
  97. $data = array();
  98. $data['file_id'] = $result;
  99. $data['file_name'] = $img_path;
  100. $data['origin_file_name'] = $_FILES["file"]["name"];
  101. $data['file_path'] = $img_path;
  102. $data['file_url'] = sns_thumb($img_path, 240);
  103. $data['state'] = 'true';
  104. /**
  105. * 整理为json格式
  106. */
  107. $output = json_encode($data);
  108. echo $output;
  109. }
  110. }
  111. ?>