DeDeCMS 织梦上传图片到服务器时,如何自动上传到又拍云存储?

一、服务器的 PHP 版本必须 >= 5.5 版本,我这里使用的是 PHP 7.0 版本;php

二、下载 php-sdk 压缩版本,我这里下载的是 php-sdk-3.3.0.zip 版本;git

三、把压缩包解压缩到 DeDeCMS 织梦的 include 目录下,以下图所示:github

我这里把压缩包重命名为 upyun-php-sdk 了

四、打开 \include\dialog\select_images_post.php 文件,作以下修改:服务器

$fullfilename = $cfg_basedir.$activepath."/".$filename;

修改成:post

$fullfilename = $activepath."/".$filename;
或者
$fullfilename = '/'.md5($_SERVER['HTTP_HOST']).$activepath."/".$filename;

而后,在该语句下面增长以下语句块:ui

/*
 * $filename_name : 1-1ZF215300B29.jpg
 * $filename : 190702/1-1ZF2152U3440.jpg
 * $activepath : /uploads/allimg
 */

# 上传图片到又拍云存储 开始
require_once DEDEINC . "/upyun-php-sdk/vendor/autoload.php";

use Upyun\Upyun;
use Upyun\Config;

$serviceConfig = new Config('服务名称', '操做员帐号', '操做员密码');
$serviceConfig->uploadType = 'AUTO';
$client = new Upyun($serviceConfig);
$local_file_path = '';
$remote_file_path = '/'.md5($_SERVER['HTTP_HOST']).$activepath.'/'.$filename;
$file = fopen($imgfile, 'r');
$client->write($remote_file_path, $file);
print_r($client);
# 上传图片到又拍云存储 结束

而后把以下语句块注释掉:spa

move_uploaded_file($imgfile, $fullfilename) or die("上传文件到 $fullfilename 失败!");
if($cfg_remote_site=='Y' && $remoteuploads == 1)
{
    //分析远程文件路径
    $remotefile = str_replace(DEDEROOT, '', $fullfilename);
    $localfile = '../..'.$remotefile;
    //建立远程文件夹
    $remotedir = preg_replace('/[^\/]*\.(jpg|gif|bmp|png)/', '', $remotefile);
    $ftp->rmkdir($remotedir);
    $ftp->upload($localfile, $remotefile);
}

这样就完成了整个过程了。又拍云存储

又拍云 php-sdk 地址: https://github.com/upyun/php-sdk/code

又拍云 php-sdk 压缩版本下载地址: https://github.com/upyun/php-sdk/releasesblog

相关文章
相关标签/搜索