Doshop.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. include_once("../untils/conn.php");
  3. mysqli_query($con, "set names utf8");
  4. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  5. // 获取客服在线时间
  6. $kefutime = $_POST['kefutime'];
  7. $puid = $_POST['puid'];
  8. $shop_name = $_POST['shop_name'];
  9. // 获取上传的文件
  10. $kefuurl = $_FILES['kefuurl'];
  11. $banner = $_FILES['banner'];
  12. $banner_one = $_FILES['banner_one'];
  13. $banner_two = $_FILES['banner_two'];
  14. // 限制文件类型为图片
  15. $allowed_types = array('jpg', 'jpeg', 'png', 'gif');
  16. $kefuurl_ext = strtolower(pathinfo($kefuurl['name'], PATHINFO_EXTENSION));
  17. $banner_ext = strtolower(pathinfo($banner['name'], PATHINFO_EXTENSION));
  18. $banner_one_ext = strtolower(pathinfo($banner_one['name'], PATHINFO_EXTENSION));
  19. $banner_two_ext = strtolower(pathinfo($banner_two['name'], PATHINFO_EXTENSION));
  20. if (!in_array($kefuurl_ext, $allowed_types) || !in_array($banner_ext, $allowed_types) || !in_array($banner_one_ext, $allowed_types) || !in_array($banner_two_ext, $allowed_types)) {
  21. echo '<script>alert("只支持上传图片文件!");window.location.href="shop.php";</script>';
  22. exit;
  23. }
  24. // 限制文件大小为2MB
  25. $max_size = 2 * 1024 * 1024; // 2MB
  26. if ($kefuurl['size'] > $max_size || $banner['size'] > $max_size || $banner_one['size'] > $max_size || $banner_two['size'] > $max_size) {
  27. echo '<script>alert("文件大小不能超过2MB!");window.location.href="shop.php";</script>';
  28. exit;
  29. }
  30. // 生成文件名
  31. $kefuurl_name = time() . '_' . rand(10000, 99999) . '.' . $kefuurl_ext;
  32. $banner_name = time() . '_' . rand(10000, 99999) . '.' . $banner_ext;
  33. $banner_one_name = time() . '_' . rand(10000, 99999) . '.' . $banner_one_ext;
  34. $banner_two_name = time() . '_' . rand(10000, 99999) . '.' . $banner_two_ext;
  35. // 获取文件临时路径
  36. $kefuurl_tmp = $kefuurl['tmp_name'];
  37. $banner_tmp = $banner['tmp_name'];
  38. $banner_one_tmp = $banner_one['tmp_name'];
  39. $banner_two_tmp = $banner_two['tmp_name'];
  40. // 将文件存储到服务器
  41. $kefuurl_path = 'uploads/' . $kefuurl_name;
  42. $banner_path = 'uploads/' . $banner_name;
  43. $banner_one_path = 'uploads/' . $banner_one_name;
  44. $banner_two_path = 'uploads/' . $banner_two_name;
  45. // 判断文件是否上传成功
  46. if (move_uploaded_file($kefuurl_tmp, $kefuurl_path)) {
  47. $sql = "UPDATE shopsy SET kefuurl='$kefuurl_path' WHERE puid='$puid'";
  48. mysqli_query($con, $sql);
  49. }
  50. if (move_uploaded_file($banner_tmp, $banner_path)) {
  51. $sql = "UPDATE shopsy SET banner='$banner_path' WHERE puid='$puid'";
  52. mysqli_query($con, $sql);
  53. }
  54. if (move_uploaded_file($banner_one_tmp, $banner_one_path)) {
  55. $sql = "UPDATE shopsy SET banner_one='$banner_one_path' WHERE puid='$puid'";
  56. mysqli_query($con, $sql);
  57. }
  58. if (move_uploaded_file($banner_two_tmp, $banner_two_path)) {
  59. $sql = "UPDATE shopsy SET banner_two='$banner_two_path' WHERE puid='$puid'";
  60. mysqli_query($con, $sql);
  61. }
  62. // 获取跳转链接
  63. $link = $_POST['link'];
  64. $link_one = $_POST['link_one'];
  65. $link_two = $_POST['link_two'];
  66. // 将数据存储到数据库中
  67. $sql = "UPDATE shopsy SET link='$link', link_one='$link_one', link_two='$link_two',shop_name='$shop_name', kefutime='$kefutime' WHERE puid='$puid'";
  68. if (mysqli_query($con, $sql)) {
  69. echo '<script>alert("操作成功!");window.location.href="shop.php";</script>';
  70. } else{
  71. echo '<script>alert("操作失败!");window.location.href="shop.php";</script>' . mysqli_error($con);
  72. }
  73. }
  74. ?>