Snsalbum.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. * ============================================================================
  16. * 控制器
  17. */
  18. class Snsalbum extends BaseMember {
  19. public function initialize() {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/snsalbum.lang.php');
  22. }
  23. /**
  24. * 图片删除
  25. */
  26. public function album_pic_del() {
  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. $member_id = session('member_id');
  58. $class_id = intval(input('param.category_id'));
  59. if ($member_id <= 0 && $class_id <= 0) {
  60. echo json_encode(array('state' => 'false', 'message' => lang('sns_upload_pic_fail'), 'origin_file_name' => $_FILES["file"]["name"]));
  61. exit;
  62. }
  63. /**
  64. * 上传图片
  65. */
  66. //上传文件保存路径
  67. if (!empty($_FILES['file']['name'])) {
  68. //设置特殊图片名称
  69. $file_name = $member_id . '_' . date('YmdHis') . rand(10000, 99999).'.png';
  70. $res = ds_upload_pic(ATTACH_MALBUM . DIRECTORY_SEPARATOR . $member_id, 'file', $file_name);
  71. if ($res['code']) {
  72. $img_path = $res['data']['file_name'];
  73. } else {
  74. $error = $res['msg'];
  75. $data['state'] = 'false';
  76. $data['message'] = $error;
  77. $data['origin_file_name'] = $_FILES['file']['name'];
  78. echo json_encode($data);
  79. exit;
  80. }
  81. } else {
  82. //未上传图片不做后面处理
  83. exit;
  84. }
  85. list($width, $height, $type, $attr) = getimagesize(ds_get_pic(ATTACH_MALBUM . DIRECTORY_SEPARATOR . $member_id, $img_path));
  86. $insert = array();
  87. $insert['ap_name'] = $img_path;
  88. $insert['ac_id'] = $class_id;
  89. $insert['ap_cover'] = $img_path;
  90. $insert['ap_size'] = intval($_FILES['file']['size']);
  91. $insert['ap_spec'] = $width . 'x' . $height;
  92. $insert['ap_uploadtime'] = TIMESTAMP;
  93. $insert['member_id'] = $member_id;
  94. $result = Db::name('snsalbumpic')->insertGetId($insert);
  95. $data = array();
  96. $data['file_id'] = $result;
  97. $data['file_name'] = $img_path;
  98. $data['origin_file_name'] = $_FILES["file"]["name"];
  99. $data['file_path'] = $img_path;
  100. $data['file_url'] = sns_thumb($img_path, 240);
  101. $data['state'] = 'true';
  102. /**
  103. * 整理为json格式
  104. */
  105. $output = json_encode($data);
  106. echo $output;
  107. }
  108. }