set_debug_mode() public méthode

设置debug模式
Since: 2012-05-29
Author: xiaobing.meng@alibaba-inc.com
public set_debug_mode ( boolean $debug_mode = true ) : void
$debug_mode boolean (Optional)
Résultat void
Exemple #1
0
 /**
  *
  */
 protected function &get_alioss()
 {
     require_once dirname(dirname(dirname(__FILE__))) . '/lib/ali-oss/sdk.class.php';
     $oss_sdk_service = new ALIOSS(null, null, $this->hostname);
     //设置是否打开curl调试模式
     $oss_sdk_service->set_debug_mode(FALSE);
     return $oss_sdk_service;
 }
Exemple #2
0
 /**
  * 初始化连接对象
  */
 private static function init()
 {
     if (!self::$conObj) {
         $ossSdkService = new ALIOSS();
         $ossSdkService->set_debug_mode(FALSE);
         //设置是否打开curl调试模式
         self::$conObj = $ossSdkService;
     }
     return self::$conObj;
 }
Exemple #3
0
 /**
  * 上传文件到oss
  * @param string $localPath
  * @param string $ossPath 在oss上的路径:
  * 	朋友圈	md5(member_id)/date('Y').date('m').date('d').'/'.pic.png
  * 	个人资料	md5(member_id)/pic.png
  * 
  * 
  */
 public static function upload($localPath, $ossPath)
 {
     $oss_sdk_service = new \ALIOSS();
     $oss_sdk_service->set_debug_mode(true);
     $bucket = BUCKET;
     $object = $ossPath;
     $file_path = $localPath;
     $response = $oss_sdk_service->upload_file_by_file($bucket, $object, $file_path);
     $header = $response->header;
     return $header['_info'];
 }
 /**
  * 上传
  *
  * @param	intval	$uid	uid	用户id
  * @param	array	$info	ci 文件上传成功返回数据
  * @return	array
  */
 public function upload($uid, $info)
 {
     $_ext = strtolower(substr($info['file_ext'], 1));
     $author = $this->_get_member_name($uid);
     $content = file_get_contents($info['full_path']);
     // 入库附件
     $this->db->replace('attachment', array('uid' => $uid, 'author' => $author, 'siteid' => $this->siteid, 'tableid' => 0, 'related' => '', 'fileext' => $_ext, 'filemd5' => $content ? md5($content) : 0, 'download' => 0, 'filesize' => $info['file_size'] * 1024));
     $id = $this->db->insert_id();
     unset($content);
     // 入库失败,返回错误且删除附件
     if (!$id) {
         @unlink($info['full_path']);
         return lang('m-145');
     }
     $remote = 0;
     $attachment = $file = substr($info['full_path'], strlen(FCPATH));
     // 附件配置信息
     $config = $this->ci->get_cache('siteinfo', SITE_ID, 'remote', SITE_ATTACH_REMOTE);
     // 远程附件模式
     if ($config && $config['SITE_ATTACH_EXTS'] && ($_exts = explode(',', $config['SITE_ATTACH_EXTS'])) && in_array($_ext, $_exts)) {
         // 根据模式来存储
         set_time_limit(0);
         if (SITE_ATTACH_REMOTE == 1) {
             // ftp附件模式
             $this->load->library('ftp');
             if ($this->ftp->connect(array('port' => $config['SITE_ATTACH_PORT'], 'debug' => FALSE, 'passive' => $config['SITE_ATTACH_PASV'], 'hostname' => $config['SITE_ATTACH_HOST'], 'username' => $config['SITE_ATTACH_USERNAME'], 'password' => $config['SITE_ATTACH_PASSWORD']))) {
                 // 连接ftp成功
                 $dir = basename(dirname($info['full_path'])) . '/';
                 $file = basename($info['full_path']);
                 $path = $config['SITE_ATTACH_PATH'] . '/' . $dir;
                 $this->ftp->mkdir($path);
                 if ($this->ftp->upload($info['full_path'], $path . $file, $config['SITE_ATTACH_MODE'], 0775)) {
                     $remote = 1;
                     $attachment = $dir . $file;
                     $file = $config['SITE_ATTACH_URL'] . '/' . $attachment;
                     unlink($info['full_path']);
                 }
                 $this->ftp->close();
             } else {
                 log_message('error', '远程附件ftp模式:ftp连接失败');
             }
         } elseif (SITE_ATTACH_REMOTE == 2) {
             // 百度云存储模式
             $file = basename(dirname($info['full_path'])) . '/' . basename($info['full_path']);
             require_once FCPATH . 'omooo/libraries/BaiduBCS/bcs.class.php';
             $bcs = new BaiduBCS($config['ak'], $config['sk'], $config['host']);
             $opt = array();
             $opt['acl'] = BaiduBCS::BCS_SDK_ACL_TYPE_PUBLIC_WRITE;
             $opt['curlopts'] = array(CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 1800);
             $response = $bcs->create_object($config['bucket'], '/' . $file, $info['full_path'], $opt);
             if ($response->status == 200) {
                 $remote = 2;
                 $attachment = $file;
                 $file = $config['SITE_ATTACH_URL'] . '/' . $attachment;
                 unlink($info['full_path']);
             } else {
                 log_message('error', '远程附件百度云存储失败');
             }
         } elseif (SITE_ATTACH_REMOTE == 3) {
             // 阿里云存储模式
             $file = basename(dirname($info['full_path'])) . '/' . basename($info['full_path']);
             require_once FCPATH . 'omooo/libraries/AliyunOSS/sdk.class.php';
             $oss = new ALIOSS($config['id'], $config['secret'], $config['host']);
             $oss->set_debug_mode(FALSE);
             $response = $oss->upload_file_by_file($config['bucket'], $file, $info['full_path']);
             if ($response->status == 200) {
                 $remote = 3;
                 $attachment = $file;
                 $file = $config['SITE_ATTACH_URL'] . '/' . $attachment;
                 unlink($info['full_path']);
             } else {
                 log_message('error', '远程附件阿里云存储模式:' . $response->body);
             }
         }
     }
     // 非远程附件补全本地地址
     if (!$remote) {
         $file = SITE_URL . $file;
     }
     $pos = strrpos($info['client_name'], '.');
     $filename = strpos($info['client_name'], 'http://') === 0 ? trim(strrchr($info['client_name'], '/'), '/') : $info['client_name'];
     $filename = $pos ? substr($filename, 0, $pos) : $filename;
     // 增加至未使用附件表
     $this->db->replace('attachment_unused', array('id' => $id, 'uid' => $uid, 'author' => $author, 'siteid' => $this->siteid, 'remote' => $remote, 'fileext' => $_ext, 'filename' => $filename, 'filesize' => $info['file_size'] * 1024, 'inputtime' => SYS_TIME, 'attachment' => $attachment, 'attachinfo' => ''));
     return array($id, $file, $_ext);
 }
Exemple #5
0
<?php

/**
 * 加载sdk包以及错误代码包
 */
require_once '../sdk.class.php';
$oss_sdk_service = new ALIOSS();
//设置是否打开curl调试模式
$oss_sdk_service->set_debug_mode(FALSE);
//设置开启三级域名,三级域名需要注意,域名不支持一些特殊符号,所以在创建bucket的时候若想使用三级域名,最好不要使用特殊字符
//$oss_sdk_service->set_enable_domain_style(TRUE);
/**
 * 测试程序
 * 目前SDK存在一个bug,在文中如果含有-&的时候,会出现找不到相关资源
 */
try {
    /**
     * Service相关操作
     */
    //get_service($oss_sdk_service);
    /**
     * Bucket相关操作
     */
    //create_bucket($oss_sdk_service);
    //delete_bucket($oss_sdk_service);
    //set_bucket_acl($oss_sdk_service);
    //get_bucket_acl($oss_sdk_service);
    //set_bucket_logging($oss_sdk_service);
    //get_bucket_logging($oss_sdk_service);
    //delete_bucket_logging($oss_sdk_service);
    //set_bucket_website($oss_sdk_service);
Exemple #6
0
 function syn_to_remote_file_server($url)
 {
     if ($GLOBALS['distribution_cfg']['OSS_TYPE'] && $GLOBALS['distribution_cfg']['OSS_TYPE'] != "NONE") {
         if ($GLOBALS['distribution_cfg']['OSS_TYPE'] == "ES_FILE") {
             $pathinfo = pathinfo($url);
             $file = $pathinfo['basename'];
             $dir = $pathinfo['dirname'];
             $dir = str_replace("public/", "", $dir);
             $filefull = SITE_DOMAIN . APP_ROOT . "/public/" . $dir . "/" . $file;
             $syn_url = $GLOBALS['distribution_cfg']['OSS_DOMAIN'] . "/es_file.php?username="******"&password="******"&file=" . $filefull . "&path=" . $dir . "/&name=" . $file . "&act=0";
             @file_get_contents($syn_url);
         } elseif ($GLOBALS['distribution_cfg']['OSS_TYPE'] == "ALI_OSS") {
             $pathinfo = pathinfo($url);
             $file = $pathinfo['basename'];
             $dir = $pathinfo['dirname'];
             $ali_oss_sdk = APP_ROOT_PATH . "system/alioss/sdk.class.php";
             if (file_exists($ali_oss_sdk)) {
                 require_once $ali_oss_sdk;
                 if (class_exists("ALIOSS")) {
                     $oss_sdk_service = new ALIOSS();
                     $oss_sdk_service->set_debug_mode(FALSE);
                     $bucket = $GLOBALS['distribution_cfg']['OSS_BUCKET_NAME'];
                     $object = $dir . "/" . $file;
                     $file_path = APP_ROOT_PATH . $dir . "/" . $file;
                     $oss_sdk_service->upload_file_by_file($bucket, $object, $file_path);
                 }
             }
         }
     }
 }
Exemple #7
0
<?php

/**
 * 加载sdk包以及错误代码包
 */
require_once '../sdk.class.php';
$oss_sdk_service = new ALIOSS();
//设置是否打开curl调试模式
$oss_sdk_service->set_debug_mode(false);
//设置开启三级域名,三级域名需要注意,域名不支持一些特殊符号,所以在创建bucket的时候若想使用三级域名,最好不要使用特殊字符
$oss_sdk_service->set_enable_domain_style(DOMAIN_THREE);
/**
 * 测试程序
 * 目前SDK存在一个bug,在文中如果含有-&的时候,会出现找不到相关资源
 */
try {
    /**
     * Service相关操作
     */
    //get_service($oss_sdk_service);
    /**
     * Bucket相关操作
     */
    //create_bucket($oss_sdk_service);
    //delete_bucket($oss_sdk_service);
    //set_bucket_acl($oss_sdk_service);
    //get_bucket_acl($oss_sdk_service);
    //set_bucket_logging($oss_sdk_service);
    //get_bucket_logging($oss_sdk_service);
    //delete_bucket_logging($oss_sdk_service);
    //set_bucket_website($oss_sdk_service);
Exemple #8
0
function oss_make_dir($obj_dir)
{
    include_once PHPDISK_ROOT . 'includes/oss/sdk.class.php';
    $obj = new ALIOSS();
    $obj->set_debug_mode(false);
    $bucket = get_oss_info('oss_bucket');
    $response = $obj->create_object_dir($bucket, get_oss_info('id') . '/' . $obj_dir);
    //_format($response);
    return $response->status == 200 ? true : false;
}
Exemple #9
0
/**
 * @param $upload
 */
function CloudStorage_Del(&$upload)
{
    global $zbp;
    $bucket = $zbp->Config('CloudStorage')->CS_Bucket;
    switch ($upload->Metas->CS_Tpye) {
        case '1':
            define('OSS_ACCESS_ID', $zbp->Config('CloudStorage')->CS_Ali_KeyID);
            //ACCESS_ID
            define('OSS_ACCESS_KEY', $zbp->Config('CloudStorage')->CS_Ali_KeySecret);
            //ACCESS_KEY
            require_once dirname(__FILE__) . '/api/oss/sdk.class.php';
            $os_service = new ALIOSS();
            $os_service->set_debug_mode(FALSE);
            $object = str_replace("http://" . $bucket . ".oss.aliyuncs.com/", '', $upload->Metas->CS_URL);
            $os_service->delete_object($bucket, $object);
            break;
        case '2':
            require_once dirname(__FILE__) . '/api/qiniu/io.php';
            require_once dirname(__FILE__) . '/api/qiniu/rs.php';
            $accessKey = $zbp->Config('CloudStorage')->CS_QNiu_KeyID;
            $secretKey = $zbp->Config('CloudStorage')->CS_QNiu_KeySecret;
            Qiniu_SetKeys($accessKey, $secretKey);
            $client = new Qiniu_MacHttpClient(null);
            $object = str_replace("http://" . $bucket . ".u.qiniudn.com/", '', $upload->Metas->CS_URL);
            Qiniu_RS_Delete($client, $bucket, $object);
            break;
        case '3':
            define('BCS_AK', $zbp->Config('CloudStorage')->CS_Baidu_KeyID);
            //AK 公钥
            define('BCS_SK', $zbp->Config('CloudStorage')->CS_Baidu_KeySecret);
            //SK 私钥
            require_once dirname(__FILE__) . '/api/bcs/bcs.class.php';
            $baidu_bcs = new BaiduBCS();
            $object = str_replace("http://bcs.duapp.com/" . $bucket, '', $upload->Metas->CS_URL);
            $baidu_bcs->delete_object($bucket, $object);
            break;
        default:
            break;
    }
    return true;
    $GLOBALS['Filter_Plugin_Upload_DelFile']['CloudStorage_Del'] = PLUGIN_EXITSIGNAL_RETURN;
}
Exemple #10
0
 function ftp_get($file, $path)
 {
     $obj = new ALIOSS();
     $obj->set_host_name($this->hostname, $this->port);
     $obj->set_debug_mode(FALSE);
     $bucket = $this->bucket;
     $file = jishigou_oss::clear($file);
     $path = jishigou_oss::clear($path);
     $options = array(ALIOSS::OSS_FILE_DOWNLOAD => $path);
     $response = $obj->get_object($bucket, $file, $options);
     $rt = jishigou_oss::status($response);
     return $rt == '2' ? 1 : 0;
 }
 private function &get_alioss()
 {
     require_once dirname(dirname(dirname(__FILE__))) . '/lib/ali-oss/sdk.class.php';
     $oss_sdk_service = new ALIOSS();
     //设置是否打开curl调试模式
     $oss_sdk_service->set_debug_mode(FALSE);
     return $oss_sdk_service;
 }
 /**
  * 上传
  *
  * @param	intval	$uid	uid	用户id
  * @param	array	$info	ci 文件上传成功返回数据
  * @param	intval	$id	id	指定附件id
  * @return	array
  */
 public function upload($uid, $info, $id = 0)
 {
     $_ext = strtolower(substr($info['file_ext'], 1));
     $author = $this->_get_member_name($uid);
     $replace = 0;
     $content = file_get_contents($info['full_path']);
     // 查询指定附件
     if ($id) {
         $row = $this->db->where('id', $id)->get('attachment')->row_array();
         if ($row) {
             $replace = 1;
             $this->siteid = intval($row['siteid']);
         } else {
             return '当前附件不存在';
         }
     }
     // 入库附件
     if (!$id) {
         $this->db->replace('attachment', array('uid' => (int) $uid, 'author' => $author, 'siteid' => $this->siteid, 'tableid' => 0, 'related' => '', 'fileext' => $_ext, 'filemd5' => $content ? md5($content) : 0, 'download' => 0, 'filesize' => $info['file_size'] * 1024));
         $id = $this->db->insert_id();
         // 入库失败,返回错误且删除附件
         if (!$id) {
             @unlink($info['full_path']);
             return lang('m-145');
         }
     }
     $remote = 0;
     $attachment = $file = (SYS_UPLOAD_DIR ? SYS_UPLOAD_DIR . '/' : '') . trim(substr($info['full_path'], strlen(SYS_UPLOAD_PATH)), '/');
     // 远程附件信息
     $remote_cfg = $this->ci->get_cache('attachment');
     if (isset($remote_cfg[$this->siteid]['ext'][$_ext]) && ($rid = $remote_cfg[$this->siteid]['ext'][$_ext])) {
         $config = $remote_cfg[$this->siteid]['data'][$rid];
         // 根据模式来存储
         set_time_limit(0);
         if ($config['type'] == 1) {
             // ftp附件模式
             $this->load->library('ftp');
             if ($this->ftp->connect(array('port' => $config['value']['port'], 'debug' => FALSE, 'passive' => $config['value']['pasv'], 'hostname' => $config['value']['host'], 'username' => $config['value']['username'], 'password' => $config['value']['password']))) {
                 // 连接ftp成功
                 $dir = basename(dirname($info['full_path'])) . '/';
                 $file = basename($info['full_path']);
                 $path = $config['value']['path'] . '/' . $dir;
                 $this->ftp->mkdir($path);
                 if ($this->ftp->upload($info['full_path'], $path . $file, $config['value']['mode'], 0775)) {
                     $remote = $config['id'];
                     $attachment = $dir . $file;
                     $file = $config['url'] . '/' . $attachment;
                     unlink($info['full_path']);
                 }
                 $this->ftp->close();
             } else {
                 log_message('error', '远程附件ftp模式:ftp连接失败');
             }
         } elseif ($config['type'] == 2) {
             // 百度云存储模式
             $file = basename(dirname($info['full_path'])) . '/' . basename($info['full_path']);
             require_once FCPATH . 'dayrui/libraries/BaiduBCS/bcs.class.php';
             $bcs = new BaiduBCS($config['value']['ak'], $config['value']['sk'], $config['value']['host']);
             $opt = array();
             $opt['acl'] = BaiduBCS::BCS_SDK_ACL_TYPE_PUBLIC_WRITE;
             $opt['curlopts'] = array(CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 1800);
             $response = $bcs->create_object($config['value']['bucket'], '/' . $file, $info['full_path'], $opt);
             if ($response->status == 200) {
                 $remote = $config['id'];
                 $attachment = $file;
                 $file = $config['url'] . '/' . $attachment;
                 unlink($info['full_path']);
             } else {
                 log_message('error', '远程附件百度云存储失败');
             }
         } elseif ($config['type'] == 3) {
             // 阿里云存储模式
             $file = basename(dirname($info['full_path'])) . '/' . basename($info['full_path']);
             require_once FCPATH . 'dayrui/libraries/AliyunOSS/sdk.class.php';
             $oss = new ALIOSS($config['value']['id'], $config['value']['secret'], $config['value']['host']);
             $oss->set_debug_mode(FALSE);
             $response = $oss->upload_file_by_file($config['value']['bucket'], $file, $info['full_path']);
             if ($response->status == 200) {
                 $remote = $config['id'];
                 $attachment = $file;
                 $file = $config['url'] . '/' . $attachment;
                 unlink($info['full_path']);
             } else {
                 log_message('error', '远程附件阿里云存储模式:' . $response->body);
             }
         } else {
             log_message('error', '远程附件类别(#' . (int) $config['type'] . ')未定义');
         }
     }
     // 非远程附件补全本地地址
     $file = !$remote ? SYS_ATTACHMENT_URL . $file : $file;
     $pos = strrpos($info['client_name'], '.');
     $filename = strpos($info['client_name'], 'http://') === 0 ? trim(strrchr($info['client_name'], '/'), '/') : $info['client_name'];
     $filename = $pos ? substr($filename, 0, $pos) : $filename;
     if ($replace) {
         // 替换主表
         $this->db->where('id', $id)->update('attachment', array('author' => $author, 'fileext' => $_ext, 'filemd5' => $content ? md5($content) : 0, 'filesize' => $info['file_size'] * 1024));
         // 更新替换已使用的附件表
         $this->db->where('id', $id)->update('attachment_' . $row['tableid'], array('uid' => $uid, 'author' => $author, 'remote' => $remote, 'fileext' => $_ext, 'filename' => $filename, 'filesize' => $info['file_size'] * 1024, 'attachment' => $attachment));
     } else {
         // 增加至未使用附件表
         $this->db->replace('attachment_unused', array('id' => $id, 'uid' => $uid, 'author' => $author, 'siteid' => $this->siteid, 'remote' => $remote, 'fileext' => $_ext, 'filename' => $filename, 'filesize' => $info['file_size'] * 1024, 'inputtime' => SYS_TIME, 'attachment' => $attachment, 'attachinfo' => ''));
     }
     return $replace ? $row : array($id, $file, $_ext);
 }