function file_deleteBAE($file) { global $_W; $baiduBCS = new BaiduBCS($_W['config']['bae']['ak'], $_W['config']['bae']['sk']); if ($file[0] == '/' && $baiduBCS->is_object_exist($_W['config']['bae']['bucket'], $file)) { $response = $baiduBCS->delete_object($_W['config']['bae']['bucket'], $file); } return TRUE; }
public function upload($imageUrls) { $conf = $this->getDI()->get('config'); $bcs = new \BaiduBCS($conf->bcs->ak, $conf->bcs->sk, $conf->bcs->host); foreach ($imageUrls as $objName => $fileUpload) { $response = $bcs->create_object($conf->bcs->bucket, $objName, $fileUpload, array('acl' => \BaiduBCS::BCS_SDK_ACL_TYPE_PUBLIC_READ)); if (!$response->isOK()) { foreach ($imageUrls as $objName => $fileUpload) { $bcs->delete_object($conf->bcs->bucket, $objName); } return false; } } return true; }
public function baidutest() { $ak = $this->input->get('ak'); $sk = $this->input->get('sk'); $host = $this->input->get('host'); $rurl = $this->input->get('rurl'); $bucket = $this->input->get('bucket'); if (!$ak || !$host || !$sk || !$bucket) { exit(lang('035')); } if (!$rurl) { exit(lang('199')); } require_once FCPATH . 'omooo/libraries/BaiduBCS/bcs.class.php'; $bcs = new BaiduBCS($ak, $sk, $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($bucket, '/test.txt', FCPATH . 'index.php', $opt); if ($response->status == 200) { if (strpos(dr_catcher_data($rurl . '/test.txt'), 'omooo.com') === FALSE) { exit(lang('200')); } $bcs->delete_object($bucket, '/test.txt'); exit('ok'); } else { exit('error'); } }
public function _delete_attachment($info) { if ($info['remote'] && isset($info['attachment']) && $info['attachment']) { // 删除远程文件 $config = $this->ci->get_cache('siteinfo', SITE_ID, 'remote', $info['remote']); // 根据模式来存储 if ($config && $info['remote'] == 1) { // ftp附件模式 set_time_limit(0); $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成功 $this->ftp->delete_file($config['SITE_ATTACH_PATH'] . '/' . $info['attachment']); $this->ftp->close(); } else { log_message('error', '远程附件ftp模式:ftp连接失败'); } } elseif ($config && $info['remote'] == 2) { // 百度云存储模式 require_once FCPATH . 'omooo/libraries/BaiduBCS/bcs.class.php'; $bcs = new BaiduBCS($config['ak'], $config['sk'], $config['host']); $bcs->delete_object($config['bucket'], '/' . $info['attachment']); } elseif ($config && $info['remote'] == 3) { // 阿里云存储模式 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->delete_object($config['bucket'], $info['attachment']); if ($response->status != 200 || $response->status != 204) { log_message('error', '(' . $info['attachment'] . ')阿里云存储删除失败:' . $response->body); } } } else { // 删除本地文件 @unlink(FCPATH . $info['attachment']); } if (isset($info['tableid'])) { $this->db->delete('attachment_' . (int) $info['tableid'], 'id=' . (int) $info['id']); } // 清空附件缓存 $this->ci->clear_cache('attachment-' . $info['id']); }
function file_delete($filename) { if (!IS_BAE) { return unlink($filename); } $arr = explode('/', ltrim($filename, './')); $bucket = C('BUCKET_PREFIX') . strtolower(array_shift($arr)); $path = implode('/', $arr); try { $bcs = new BaiduBCS(); $response = $bcs->delete_object($bucket, '/' . $path); return $response->isOK() ? true : false; } catch (Exception $e) { return false; } }
echo "Create bucket[{$bucket}] success\n"; //step2. create an object sleep(3); $response = $baiduBCS->create_object($bucket, $object, $fileUpload); if (!$response->isOK()) { die("Create object failed."); } echo "Create object[{$object}] in bucket[{$bucket}] success\n"; //step3. download this object sleep(3); $opt = array("fileWriteTo" => $fileWriteTo); $response = $baiduBCS->get_object($bucket, $object, $opt); if (!$response->isOK()) { die("Download object failed."); } echo "Download object[{$object}] in bucket[{$bucket}] success. And write to [{$fileWriteTo}]\n"; //step4. delete this object sleep(3); $response = $baiduBCS->delete_object($bucket, $object); if (!$response->isOK()) { die("Delete object failed."); } echo "Delete object[{$object}] in bucket[{$bucket}] success\n"; //step5. delete this bucket sleep(3); $response = $baiduBCS->delete_bucket($bucket); if (!$response->isOK()) { die("Delete bucket failed."); } echo "Delete bucket[{$bucket}] success\n"; }
function del_attachments_from_bcs($file) { require_once 'bcs.class.php'; $bcs_options = get_option('bcs_options', TRUE); $bcs_bucket = attribute_escape($bcs_options['bucket']); if (false === getenv('HTTP_BAE_ENV_AK')) { $bcs_ak = attribute_escape($bcs_options['ak']); } if (false === getenv('HTTP_BAE_ENV_SK')) { $bcs_sk = attribute_escape($bcs_options['sk']); } if (!is_object($baidu_bcs)) { $baidu_bcs = new BaiduBCS($bcs_ak, $bcs_sk); } $bucket = $bcs_bucket; $upload_dir = wp_upload_dir(); $object = str_replace($upload_dir['basedir'], '', $file); $object = ltrim($object, '/'); $object = str_replace('http://bcs.duapp.com/' . $bucket, '', $object); $baidu_bcs->delete_object($bcs_bucket, $object); return $file; }
/** * @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; }
public function _delete_attachment($info) { if ($info['remote'] && isset($info['attachment']) && $info['attachment']) { // 删除远程文件 $config = $this->ci->get_cache('attachment', $this->siteid, 'data', $info['remote']); // 根据模式来存储 if ($config && $config['type'] == 1) { // ftp附件模式 set_time_limit(0); $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成功 $this->ftp->delete_file($config['value']['path'] . '/' . $info['attachment']); $this->ftp->close(); } else { log_message('error', '远程附件ftp模式:ftp连接失败'); } } elseif ($config && $config['type'] == 2) { // 百度云存储模式 require_once FCPATH . 'dayrui/libraries/BaiduBCS/bcs.class.php'; $bcs = new BaiduBCS($config['value']['ak'], $config['value']['sk'], $config['value']['host']); $bcs->delete_object($config['value']['bucket'], '/' . $info['attachment']); } elseif ($config && $config['type'] == 3) { // 阿里云存储模式 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->delete_object($config['value']['bucket'], $info['attachment']); if ($response->status != 200 || $response->status != 204) { log_message('error', '(' . $info['attachment'] . ')阿里云存储删除失败:' . $response->body); } } } else { // 删除本地文件 $file = SYS_UPLOAD_PATH . '/' . $info['attachment']; $file = str_replace('member/uploadfile/member/uploadfile', 'member/uploadfile', $file); @unlink($file); } if (isset($info['tableid'])) { $this->db->delete('attachment_' . (int) $info['tableid'], 'id=' . (int) $info['id']); } // 清空附件缓存 $this->ci->clear_cache('attachment-' . $info['id']); }