DeDeCMS 織夢上傳圖片到服務器時,如何自動上傳到又拍雲存儲?

一、服務器的 PHP 版本必須 >= 5.5 版本,我這裏使用的是 PHP 7.0 版本;

二、下載 php-sdk 壓縮版本,我這裏下載的是 php-sdk-3.3.0.zip 版本;

三、把壓縮包解壓縮到 DeDeCMS 織夢的 include 目錄下,以下圖所示:php

我這裏把壓縮包重命名爲 upyun-php-sdk 了

我這裏把壓縮包重命名爲 upyun-php-sdk 了git

若是是在 CentOS 上操做,則代碼以下:github

cp -r upyun-php-sdk /zls/server/apache/htdocs/www.baidu.com/zlslhxwww/include/
即把 upyun-php-sdk 整個文件夾包括子文件夾和文件 複製到 include 目錄下,複製後結構爲 /include/upyun-php-sdk

四、打開 \include\dialog\select_images_post.php 文件,作以下修改:apache

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

修改成:服務器

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

 而後,在該語句下面增長以下語句塊:post

/*
 * $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);
# 上傳圖片到又拍雲存儲 結束

而後把以下語句塊註釋掉:ui

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);
}

這樣就完成了整個過程了。spa

附帶:又拍雲存儲

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

又拍雲 php-sdk 壓縮版本下載地址: https://github.com/upyun/php-sdk/releases

php-sdk-3.3.0.zip 具體下載地址:https://github.com/upyun/php-sdk/releases/download/3.3.0/php-sdk-3.3.0.zip

相關文章
相關標籤/搜索