Snsalbum.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * 买家相册
  4. */
  5. namespace app\home\controller;
  6. use think\facade\Lang;
  7. use think\facade\Db;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Snsalbum extends BaseMember
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/snsalbum.lang.php');
  21. }
  22. /**
  23. * 图片删除
  24. */
  25. public function album_pic_del()
  26. {
  27. $ids = input('param.id');
  28. if (empty($ids)) {
  29. ds_json_encode(10001, lang('album_parameter_error'));
  30. };
  31. if (!empty($ids) && is_array($ids)) {
  32. $id = $ids;
  33. } else {
  34. $id[] = intval($ids);
  35. }
  36. foreach ($id as $v) {
  37. $v = intval($v);
  38. if ($v <= 0)
  39. continue;
  40. $ap_info = Db::name('snsalbumpic')->where(array('ap_id' => $v, 'member_id' => session('member_id')))->find();
  41. if (empty($ap_info))
  42. continue;
  43. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_MALBUM . DIRECTORY_SEPARATOR . session('member_id') . DIRECTORY_SEPARATOR . $ap_info['ap_cover']);
  44. $res = Db::name('snsalbumpic')->delete($ap_info['ap_id']);
  45. }
  46. if ($res) {
  47. ds_json_encode(10000, lang('album_class_pic_del_succeed'));
  48. }
  49. }
  50. /**
  51. * 上传图片
  52. *
  53. * @param
  54. * @return
  55. */
  56. public function swfupload()
  57. {
  58. $member_id = session('member_id');
  59. $class_id = intval(input('param.category_id'));
  60. if ($member_id <= 0 && $class_id <= 0) {
  61. echo json_encode(array('state' => 'false', 'message' => lang('sns_upload_pic_fail'), 'origin_file_name' => $_FILES["file"]["name"]));
  62. exit;
  63. }
  64. /**
  65. * 上传图片
  66. */
  67. //上传文件保存路径
  68. if (!empty($_FILES['file']['name'])) {
  69. //设置特殊图片名称
  70. $file_name = $member_id . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  71. $res = ds_upload_pic(ATTACH_MALBUM . DIRECTORY_SEPARATOR . $member_id, 'file', $file_name);
  72. if ($res['code']) {
  73. $img_path = $res['data']['file_name'];
  74. } else {
  75. $error = $res['msg'];
  76. $data['state'] = 'false';
  77. $data['message'] = $error;
  78. $data['origin_file_name'] = $_FILES['file']['name'];
  79. echo json_encode($data);
  80. exit;
  81. }
  82. } else {
  83. //未上传图片不做后面处理
  84. exit;
  85. }
  86. list($width, $height, $type, $attr) = getimagesize(ds_get_pic(ATTACH_MALBUM . DIRECTORY_SEPARATOR . $member_id, $img_path));
  87. $insert = array();
  88. $insert['ap_name'] = $img_path;
  89. $insert['ac_id'] = $class_id;
  90. $insert['ap_cover'] = $img_path;
  91. $insert['ap_size'] = intval($_FILES['file']['size']);
  92. $insert['ap_spec'] = $width . 'x' . $height;
  93. $insert['ap_uploadtime'] = TIMESTAMP;
  94. $insert['member_id'] = $member_id;
  95. $result = Db::name('snsalbumpic')->insertGetId($insert);
  96. $data = array();
  97. $data['file_id'] = $result;
  98. $data['file_name'] = $img_path;
  99. $data['origin_file_name'] = $_FILES["file"]["name"];
  100. $data['file_path'] = $img_path;
  101. $data['file_url'] = sns_thumb($img_path, 240);
  102. $data['state'] = 'true';
  103. /**
  104. * 整理为json格式
  105. */
  106. $output = json_encode($data);
  107. echo $output;
  108. }
  109. }