doubu1853 2018-11-27 07:32
浏览 93

如何将使用CSS更改的图像保存到数据库中

I have an image and I want to be able to apply one or more effects to the image through css (eg. blur). I want to store the modified version of the image to the database. How can I do that? This is my code. Html:

<img src="avatar.jpg" class="blur"></img>    
<button type="submit" name="uploadimg" class="btn btn-info" style="width: 90px; height: 40px; margin-top: 2%;"> <a class="upload" href=""></a>upload</button>

css:

.blur {
    -webkit-filter: blur(5px);
            filter: blur(5px);
}

This is my upload script:

if (isset($_POST['uploadimg'])) {

  $avatar = $_FILES['avatar'];
  $avatar_name = $_FILES['avatar']['name'];
  $avatar_tmpname = $_FILES['avatar']['tmp_name'];
  $avatar_size =  $_FILES['avatar']['size'];
  $avatar_type = $_FILES['avatar']['type'];
  $avatar_ext = pathinfo($avatar_name, PATHINFO_EXTENSION);

  if (!empty($avatar_name)) {
    if ($avatar_size <= 25000000) {
      if ($avatar_ext == "jpg" || $avatar_ext == "jpeg" ||$avatar_ext == "png" ) {
        $chars= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $rand_dir_name = substr(str_shuffle($chars),0,15);
        mkdir("uploads/$rand_dir_name");
        $final_file = "uploads/$rand_dir_name/$avatar_name";

        $upload = move_uploaded_file($avatar_tmpname, $final_file);
        if ($upload) {
          unlink("$avatar_path");
          $msg = "file uploaded successfully ";
          $query = "UPDATE users SET avatar_path='$final_file' WHERE id='$id'";
          $fire = mysqli_query($con,$query) or die("can not insert file path into database".mysqli_error($con));
          $query = "UPDATE likes SET avatar_path='$final_file' WHERE user_id='$id'";
          $fire = mysqli_query($con,$query) or die("can not insert file path into database".mysqli_error($con));
          $query = "UPDATE photos SET avatar_path='$final_file' WHERE uid='$id'";
          $fire = mysqli_query($con,$query) or die("can not insert file path into database".mysqli_error($con));

          if ($fire) {
            $msg .=" and also inserted into database";
          }

          # code...
        } else {
          echo "only jpg,jpeg,png, type format allowed";
        }
      } else {
        echo "file size is too large";
      }
    } else {
      echo "please select an image to upload";
    }
  }
}
}

It saves the avatar path to the database and saves the image in a folder. But how can I save the modified version of the image instead?

  • 写回答

2条回答 默认 最新

  • dongluan1901 2018-11-27 08:46
    关注

    Store image source in a database, and optional CSS effects selected by user store in separate columns, for example, you can create a new column in image table, named "is_blur" and if the user has selected this option set it to true.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用