php - 将裁剪后的图像保存到本地服务器并将其 URL 保存到 MySQL 数据库

标签 php mysql image

我正在使用cropit裁剪图像。

  <body>
    <div class="image-editor">
      <input type="file" class="cropit-image-input">
      <!-- .cropit-image-preview-container is needed for background image to work -->
      <div class="cropit-image-preview-container">
        <div class="cropit-image-preview"></div>
      </div>
      <div class="image-size-label">
        Resize image
      </div>
      <input type="range" class="cropit-image-zoom-input">
      <button class="export">Save</button>
    </div>

    <script>
      $(function() {
        $('.image-editor').cropit({
          exportZoom: 1.25,
          imageBackground: true,
          imageBackgroundBorderWidth: 10,
          imageState: {
            src: '../image/default-avatar.png'
          }
        });

        $('.export').click(function() {
          var imageData = $('.image-editor').cropit('export');
          window.open(imageData);

        });
      });
    </script>
  </body>

我遇到了两个问题:

  1. 当我进行裁剪并单击“保存”按钮时,裁剪后的图像将在新窗口中打开。我希望它不应该在新窗口中打开,而是裁剪后的图像应该保存到相关的用户文件夹,例如: ROOT_PATH.'user/upload/'.$row['用户名'].'/avatar/big/'
  2. 我还想将最新裁剪后的图像 URL 保存到 MySQL 数据库的 AvatarImage 列中。

在下面找到MySQL数据库信息:

数据库名称:ara

数据库用户:root

数据库密码:

数据库地址:127.0.0.1

最佳答案

您必须使用php对图像文件进行base64编码,并将图像保存到文件目录中, 请尝试欺骗现有的链接

How to create and save image to a website folder from a base64 encoded data/string using PHP

关于php - 将裁剪后的图像保存到本地服务器并将其 URL 保存到 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30161454/

相关文章:

c# - 在 C# 中解密用 PHP 加密的字符串 (Blowfish)

javascript - 关闭 fancybox 时将变量从 fancybox 传递到父页面

mysql - 如何更改数据库中的整行以将 l 更改为左,将 r 更改为右

php按多类别和一一过滤

image - 在Flutter中将 Assets 图片用作标签图标

php - 我想使用 php 在 css 中的每个元素中添加我的类名

bool /tinyint(1) 类型的 PHP if 语句

php - 从 PHP 端处理 MySQL 事务 : strategy and best practices

html - 获取图像特定区域的所有多边形坐标?

C++如何使用CWnd *对象加载图片?