阿里云OSS for phpcmsV9

1、下载OSS的SDK,下载地址
http://code.taobao.org/p/thered/src/ThinkPHP/Lib/Service/oss/
http://code1.okbase.net/codefile/sdk.class.php_2014120428044_105.htm

http://code.taobao.org/p/fanshop/src/w8/system/alioss/sdk.class.php

http://code.taobao.org/p/fanshop/diff/2/w8/system/alioss/sdk.class.php

2、解压SDK压缩包,打开conf.inc.php,修改Access Key ID和Access Key Secret为自己的


3、将SDK包中的以下文件放入红色框的路径

4、打开phpcms\modules\admin\templates\setting.tpl.php
搜索

<td class="y-bg"><input type="text" class="input-text" name="setconfig[upload_url]" id="upload_url" size="50" value="<?php echo $upload_url?>" /></td>
  </tr>

在下方添加

<!--阿里云OSS配置 S-->
  <tr>
    <th width="120"><?php echo L('setting_oss_enable')?></th>
    <td class="y-bg">
    <input name="setconfig[oss_enable]" value="1"  type="radio"  <?php echo ($oss_enable=='1') ? ' checked' : ''?>> <?php echo L('setting_yes')?>&nbsp;&nbsp;&nbsp;&nbsp;
  <input name="setconfig[oss_enable]" value="0" type="radio"  <?php echo ($oss_enable=='0') ? ' checked' : ''?>> <?php echo L('setting_no')?></td>
  </tr> 
  <tr>
    <th width="120"><?php echo L('setting_oss_id')?></th>
    <td class="y-bg">
      <input type="text" class="input-text" name="setconfig[oss_id]" id="oss_id" size="50" value="<?php echo $oss_id?>" />
      <div class="onShow">还没有?<a href="http://help.aliyun.com/manual?spm=0.0.0.111.8BPOua&helpId=786" target="_blank">到这里获取API 密钥</a></div>
    </td>
  </tr>       
  <tr>
    <th width="120"><?php echo L('setting_oss_secret')?></th>
    <td class="y-bg"><input type="password" class="input-text" name="setconfig[oss_secret]" id="oss_secret" size="50" value="<?php echo $oss_secret?>" /></td>
  </tr>
  <tr>
    <th width="120"><?php echo L('setting_oss_bucket')?></th>
    <td class="y-bg"><input type="text" class="input-text" name="setconfig[oss_bucket]" id="oss_bucket" size="50" value="<?php echo $oss_bucket?>" /></td>
  </tr>     
  <tr>
    <th width="120"><?php echo L('setting_oss_path')?></th>
    <td class="y-bg"><input type="text" class="input-text" name="setconfig[oss_path]" id="oss_path" size="50" value="<?php echo $oss_path?>" /></td>
  </tr>       
  <tr>
    <th width="120"><?php echo L('setting_oss_upload_url')?></th>
    <td class="y-bg"><input type="text" class="input-text" name="setconfig[oss_upload_url]" id="oss_upload_url" size="50" value="<?php echo $oss_upload_url?>" /></td>
  </tr>
<!--阿里云OSS配置 E-->

=====打开phpcms\languages\zh-cn\admin.lang.php
在?>前加入

$LANG['setting_oss_enable'] = '启用阿里云存储';
$LANG['setting_oss_id'] = 'Access Key ID';
$LANG['setting_oss_secret'] = 'Access Key Secret';
$LANG['setting_oss_bucket'] = 'Bucket名称';
$LANG['setting_oss_path'] = 'OSS上的图片目录';
$LANG['setting_oss_upload_url'] = '访问路径';

打开phpcms\modules\admin\setting.php,
搜索

$setting['errorlog_size'] = trim($_POST['setting']['errorlog_size']);

在下方添加

                //阿里云云存储配置
                $setting['oss_enable'] = intval($_POST['setconfig']['oss_enable']);
                $setting['oss_id'] = trim($_POST['setconfig']['oss_id']);
                $setting['oss_secret'] = $_POST['setconfig']['oss_secret'];
                $setting['oss_bucket'] = trim($_POST['setconfig']['oss_bucket']);
                $setting['oss_path'] = trim($_POST['setconfig']['oss_path']);
                $setting['oss_upload_url'] = trim($_POST['setconfig']['oss_upload_url']);

=====打开phpcms\modules\attachment\attachments.php
搜索

$this->groupid = param::get_cookie('_groupid') ? param::get_cookie('_groupid') : 8;

在下方加入

$this->oss = getcache('common','commons');        //载入云存储配置的缓存

再搜索

echo $aids[0].','.$this->upload_url.$attachment->uploadedfiles[0]['filepath'].','.$attachment->uploadedfiles[0]['isimage'].','.$filename;

替换

if($this->oss['oss_enable']){        //图片云存储
  echo $aids[0].','.$this->oss['oss_upload_url'].$attachment->uploadedfiles[0]['filepath'].','.$attachment->uploadedfiles[0]['isimage'].','.$filename;
  }else{
  echo $aids[0].','.$this->upload_url.$attachment->uploadedfiles[0]['filepath'].','.$attachment->uploadedfiles[0]['isimage'].','.$filename;
}

=====打开phpcms\libs\classes\attachment.class.php
搜索

var $site = array();

在下方加入

var $oss; //云存储

再搜索

$this->upload_dir = $upload_dir;

在下方加入

$this->oss = getcache('common','commons');        //载入云存储配置的缓存

再搜索

if($watermark_enable) {
      $image->watermark($savefile, $savefile);
}

在下方加入

if($this->oss['oss_enable']){        //图片云存储
    pc_base::load_app_class('sdk', '' ,0);        //载入OSS类
    $oss_sdk_service = new ALIOSS();
    $oss_sdk_service->set_debug_mode(FALSE);        //设置是否打开curl调试模式
    $oss_sdk_service->upload_file_by_file($this->oss['oss_bucket'],$this->oss['oss_path'].$filepath,$this->upload_root.$filepath);
}

再搜索

if($thumbs) foreach($thumbs as $thumb) @unlink($thumb);

在下方加入

//删除OSS上的图
if($this->oss['oss_enable']){        //图片云存储
    pc_base::load_app_class('sdk', 'attachment' ,0);        //载入OSS类
    $oss_sdk_service = new ALIOSS();
    $oss_sdk_service->set_debug_mode(FALSE);        //设置是否打开curl调试模式
    $oss_sdk_service->delete_object($this->oss['oss_bucket'],$this->oss['oss_path'].$r['filepath']);
}

5、后台设置(设置 > 相关设置 > 基本设置),对照以下图片
phpcms和uploadfile这个两个都需要手工创建
OSS上的设置
阿里云OSS for phpcmsV9_第1张图片

5、最后一点就是将相关模型字段中的editor修改为不保存远程图片:
阿里云OSS for phpcmsV9_第2张图片

更新缓存!



你可能感兴趣的:(阿里云OSS for phpcmsV9)