1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- include_once("../untils/conn.php");
- mysqli_query($con, "set names utf8");
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- // 获取客服在线时间
- $kefutime = $_POST['kefutime'];
- $puid = $_POST['puid'];
- $shop_name = $_POST['shop_name'];
- // 获取上传的文件
- $kefuurl = $_FILES['kefuurl'];
- $banner = $_FILES['banner'];
- $banner_one = $_FILES['banner_one'];
- $banner_two = $_FILES['banner_two'];
- // 限制文件类型为图片
- $allowed_types = array('jpg', 'jpeg', 'png', 'gif');
- $kefuurl_ext = strtolower(pathinfo($kefuurl['name'], PATHINFO_EXTENSION));
- $banner_ext = strtolower(pathinfo($banner['name'], PATHINFO_EXTENSION));
- $banner_one_ext = strtolower(pathinfo($banner_one['name'], PATHINFO_EXTENSION));
- $banner_two_ext = strtolower(pathinfo($banner_two['name'], PATHINFO_EXTENSION));
- 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)) {
- echo '<script>alert("只支持上传图片文件!");window.location.href="shop.php";</script>';
- exit;
- }
- // 限制文件大小为2MB
- $max_size = 2 * 1024 * 1024; // 2MB
- if ($kefuurl['size'] > $max_size || $banner['size'] > $max_size || $banner_one['size'] > $max_size || $banner_two['size'] > $max_size) {
- echo '<script>alert("文件大小不能超过2MB!");window.location.href="shop.php";</script>';
- exit;
- }
- // 生成文件名
- $kefuurl_name = time() . '_' . rand(10000, 99999) . '.' . $kefuurl_ext;
- $banner_name = time() . '_' . rand(10000, 99999) . '.' . $banner_ext;
- $banner_one_name = time() . '_' . rand(10000, 99999) . '.' . $banner_one_ext;
- $banner_two_name = time() . '_' . rand(10000, 99999) . '.' . $banner_two_ext;
- // 获取文件临时路径
- $kefuurl_tmp = $kefuurl['tmp_name'];
- $banner_tmp = $banner['tmp_name'];
- $banner_one_tmp = $banner_one['tmp_name'];
- $banner_two_tmp = $banner_two['tmp_name'];
- // 将文件存储到服务器
- $kefuurl_path = 'uploads/' . $kefuurl_name;
- $banner_path = 'uploads/' . $banner_name;
- $banner_one_path = 'uploads/' . $banner_one_name;
- $banner_two_path = 'uploads/' . $banner_two_name;
- // 判断文件是否上传成功
- if (move_uploaded_file($kefuurl_tmp, $kefuurl_path)) {
- $sql = "UPDATE shopsy SET kefuurl='$kefuurl_path' WHERE puid='$puid'";
- mysqli_query($con, $sql);
- }
- if (move_uploaded_file($banner_tmp, $banner_path)) {
- $sql = "UPDATE shopsy SET banner='$banner_path' WHERE puid='$puid'";
- mysqli_query($con, $sql);
- }
- if (move_uploaded_file($banner_one_tmp, $banner_one_path)) {
- $sql = "UPDATE shopsy SET banner_one='$banner_one_path' WHERE puid='$puid'";
- mysqli_query($con, $sql);
- }
- if (move_uploaded_file($banner_two_tmp, $banner_two_path)) {
- $sql = "UPDATE shopsy SET banner_two='$banner_two_path' WHERE puid='$puid'";
- mysqli_query($con, $sql);
- }
- // 获取跳转链接
- $link = $_POST['link'];
- $link_one = $_POST['link_one'];
- $link_two = $_POST['link_two'];
- // 将数据存储到数据库中
- $sql = "UPDATE shopsy SET link='$link', link_one='$link_one', link_two='$link_two',shop_name='$shop_name', kefutime='$kefutime' WHERE puid='$puid'";
- if (mysqli_query($con, $sql)) {
- echo '<script>alert("操作成功!");window.location.href="shop.php";</script>';
- } else{
- echo '<script>alert("操作失败!");window.location.href="shop.php";</script>' . mysqli_error($con);
- }
- }
- ?>
|