4

typecho七牛云上传图片(实现复制粘贴上传图片)

 3 years ago
source link: https://surest.cn/archives/114/comment-page-1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

typecho七牛云上传图片(复制粘贴)

毕竟图片放置到自己的服务器端有点不合适,所以还是想着有什么好办法能够直接放到七牛云吧

实现流程大概如下

  • 获取编辑器粘贴事件,获取图片base64编码
  • 上传base64编码到七牛云
  • 根据返回的key, 拼接七牛云图片地址插入到markdown中

目前存在隐患和不足的地方,请注意

  • 无需鉴权即可获取 七牛云 上传凭证
  • AK+SK需要在代码中进行配置

php > 7.0
会一点composer(不会也没事)
composer 环境, 具体如何安装composer, 这里不作赘述

安装七牛云 SDK

进入项目根目录

创建包目录

在根目录下, 创建 vender 目录

创建composer.json

vi composer.json
>   

{
    "name": "root/surest_typecho",
    "authors": [
        {
            "name": "RA31",
            "email": "[email protected]"
        }
    ],
    "require": {
        "qiniu/php-sdk": "^7.2"
    }
}

执行 composer install

admin/auth 下放置这个文件

https://github.com/surest-sky/example/blob/master/typecho/auth/qiniu.php

tools 目录下放置这个文件

https://github.com/surest-sky/example/blob/master/typecho/qiniu_upload.php

进入admin/write-post.php , 插入语句

在最后一行插入 <?php include_once '../tools/qiniu_upload.php'?>

进入编辑器, 复制粘贴, 图片即可

复制粘贴上传七牛玉只支持

  • 微信复制图片
  • qq 截图等等

相关的配置 AK 和 SK 用的是我的密钥,建议自己更改,这个仅做测试使用

配合添加配置文件

修改AK和SK

进入 auth/qiniu.php

修改 $config 配置

进入 tools/qiniu_upload.php

const DOMAIN = 'http://cdn.surest.cn/'  // cdn 域名
const URL = "http://surest.cn/admin/auth/qiniu.php" // 例如 将 http://surest.cn/admin 修改为 你的博客后台访问地址

进入编辑器 , 复制粘贴即可图片描述...

1564290306150.gif

本文由 邓尘锋 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Jan 2, 2020 at 09:20 am


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK