删除object
public delete_object ( $bucket, string $object, array $options = null ) : ResponseCore | ||
$object | string | (Required) |
$options | array | (Optional) |
Résultat | ResponseCore |
public static function deleteFile($filepath) { // 获取插件配置 $option = self::getConfig(); self::initSDK(); $obj = new ALIOSS($option->accessid, $option->accesskey, $option->endpoint); $obj->delete_object($option->bucket, $filepath); }
public function aliyuntest() { $id = $this->input->get('id'); $host = $this->input->get('host'); $rurl = $this->input->get('rurl'); $secret = $this->input->get('secret'); $bucket = $this->input->get('bucket'); if (!$id || !$host || !$secret || !$bucket) { exit(lang('035')); } if (!$rurl) { exit(lang('199')); } require_once FCPATH . 'omooo/libraries/AliyunOSS/sdk.class.php'; $oss = new ALIOSS($id, $secret, $host); $response = $oss->upload_file_by_file($bucket, 'test.txt', FCPATH . 'index.php'); if ($response->status == 200) { $oss->delete_object($bucket, 'test.txt'); if (strpos(dr_catcher_data($rurl . '/test.txt'), 'omooo.com') === FALSE) { exit(lang('200')); } exit('ok'); } else { exit($response->body); } }
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_remote_delete($file) { global $_W; if (empty($file)) { return true; } if ($_W['setting']['remote']['type'] == '1') { require IA_ROOT . '/framework/library/ftp/ftp.php'; $ftp_config = array('hostname' => $_W['setting']['remote']['ftp']['host'], 'username' => $_W['setting']['remote']['ftp']['username'], 'password' => $_W['setting']['remote']['ftp']['password'], 'port' => $_W['setting']['remote']['ftp']['port'], 'ssl' => $_W['setting']['remote']['ftp']['ssl'], 'passive' => $_W['setting']['remote']['ftp']['pasv'], 'timeout' => $_W['setting']['remote']['ftp']['timeout'], 'rootdir' => $_W['setting']['remote']['ftp']['dir']); $ftp = new Ftp($ftp_config); if (true === $ftp->connect()) { if ($ftp->delete_file($file)) { return true; } else { return error(1, '删除附件失败,请检查配置并重新删除'); } } else { return error(1, '删除附件失败,请检查配置并重新删除'); } } elseif ($_W['setting']['remote']['type'] == '2') { require IA_ROOT . '/framework/library/alioss/sdk.class.php'; $oss = new ALIOSS($_W['setting']['remote']['alioss']['key'], $_W['setting']['remote']['alioss']['secret'], $_W['setting']['remote']['alioss']['ossurl']); $response = $oss->delete_object($_W['setting']['remote']['alioss']['bucket'], $file); if ($response->status == 204) { return true; } else { return error(1, '删除oss远程文件失败'); } } return true; }
protected function publish($dat = []) { $id = (int) $dat['id']; $htm = ''; if ($id) { $dat = D(CONTROLLER_NAME)->complete_fields($dat); $this->data = ['item' => $dat]; layout(false); $htm = $this->fetch('view'); $fnm = 'article/content/' . $id . '.html'; import('Org.AliyunOss.sdk'); $oss = new \ALIOSS(); $oss->delete_object('cjstatic', $fnm); $ret = $oss->upload_file_by_content('cjstatic', $fnm, ['content' => $dat['content'], 'Content-Encoding' => 'UTF-8', 'Expires' => date('Y-m-d H:i:s', strtotime('1 days'))]); } return $dat; }
/** * 删除远程服务器上的单个文件 * @static * @param $file * @return void */ function delete_remote_file($file) { //获取WP配置信息 $oss_options = get_option('oss_options', TRUE); $oss_bucket = attribute_escape($oss_options['bucket']); $oss_ak = attribute_escape($oss_options['ak']); $oss_sk = attribute_escape($oss_options['sk']); $oss_host = attribute_escape($oss_options['host']); if ($oss_host == null || $oss_host == '') { $oss_host = 'oss.aliyuncs.com'; } //得到远端路径 $del_file_path = str_replace(get_home_path(), '', $file); //_logged('2delete.txt',"del_file_path=$del_file_path"); try { //实例化存储对象 if (!is_object($aliyun_oss)) { $aliyun_oss = new ALIOSS($oss_ak, $oss_sk, $oss_host); } //删除文件 $aliyun_oss->delete_object($oss_bucket, $del_file_path); } catch (Exception $ex) { } return $file; }
function file_remote_delete($file) { global $_W; if (empty($file)) { return true; } if ($_W['setting']['remote']['type'] == '1') { require_once IA_ROOT . '/framework/library/ftp/ftp.php'; $ftp_config = array('hostname' => $_W['setting']['remote']['ftp']['host'], 'username' => $_W['setting']['remote']['ftp']['username'], 'password' => $_W['setting']['remote']['ftp']['password'], 'port' => $_W['setting']['remote']['ftp']['port'], 'ssl' => $_W['setting']['remote']['ftp']['ssl'], 'passive' => $_W['setting']['remote']['ftp']['pasv'], 'timeout' => $_W['setting']['remote']['ftp']['timeout'], 'rootdir' => $_W['setting']['remote']['ftp']['dir']); $ftp = new Ftp($ftp_config); if (true === $ftp->connect()) { if ($ftp->delete_file($file)) { return true; } else { return error(1, '删除附件失败,请检查配置并重新删除'); } } else { return error(1, '删除附件失败,请检查配置并重新删除'); } } elseif ($_W['setting']['remote']['type'] == '2') { require_once IA_ROOT . '/framework/library/alioss/sdk.class.php'; $oss = new ALIOSS($_W['setting']['remote']['alioss']['key'], $_W['setting']['remote']['alioss']['secret'], $_W['setting']['remote']['alioss']['ossurl']); $response = $oss->delete_object($_W['setting']['remote']['alioss']['bucket'], $file); if ($response->status == 204) { return true; } else { return error(1, '删除oss远程文件失败'); } } elseif ($_W['setting']['remote']['type'] == '3') { require_once IA_ROOT . '/framework/library/qiniu/autoload.php'; $auth = new Qiniu\Auth($_W['setting']['remote']['qiniu']['accesskey'], $_W['setting']['remote']['qiniu']['secretkey']); $bucketMgr = new Qiniu\Storage\BucketManager($auth); $error = $bucketMgr->delete($_W['setting']['remote']['qiniu']['bucket'], $file); if ($error instanceof Qiniu\Http\Error) { if ($error->code() == 612) { return true; } return error(1, '删除七牛远程文件失败'); } else { return true; } } return true; }
/** * @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; }
function ossdel($file_path) { require_once CSCMSPATH . 'uploads/oss/sdk.class.php'; if (substr($file_path, 0, 1) == '/') { $file_path = substr($file_path, 1); } $obj = new ALIOSS(); $response = $obj->delete_object(BUCKET, $file_path); if ($response->status == 200) { return true; } else { return false; } }
/** * 删除文件 * * @access public * @param array $content 文件相关信息 * @return string */ public static function deleteHandle(array $content) { $options = Typecho_Widget::widget('Widget_Options'); $access_id = $options->plugin('AliUpload')->access_id; $access_key = $options->plugin('AliUpload')->access_key; $bucket = $options->plugin('AliUpload')->bucket; $oss_service = new ALIOSS($access_id, $access_key); $response = $oss_service->delete_object($bucket, $content['attachment']->path); return $response->isOk(); }
function ftp_delete($path) { $obj = new ALIOSS(); $obj->set_host_name($this->hostname, $this->port); $obj->set_debug_mode(FALSE); $bucket = $this->bucket; $path = jishigou_oss::clear($path); $path = str_replace($bucket . '/', '', $path); $response = $obj->delete_object($bucket, $path); $rt = jishigou_oss::status($response); return $rt == '2' ? 1 : 0; }
/** * 删除远程服务器上的单个文件 * * @param $file * @return mixed */ function delete_remote_file($file) { if (!false == strpos($file, '@!')) { return $file; } $oss_options = get_option('oss_options', TRUE); $oss_bucket = esc_attr($oss_options['bucket']); $oss_ak = esc_attr($oss_options['ak']); $oss_sk = esc_attr($oss_options['sk']); $oss_upload_path = trim($oss_options['path'], '/'); $wp_uploads = wp_upload_dir(); $del_file = str_replace($wp_uploads['basedir'], '', $file); $del_file = ltrim($oss_upload_path . '/' . ltrim($del_file, '/'), '/'); if (!is_object($aliyun_oss)) { $aliyun_oss = new ALIOSS($oss_ak, $oss_sk); } $aliyun_oss->delete_object($oss_bucket, $del_file); return $file; }
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']); }