public function create_object_by_content($bucket, $object, $content, $opt = array()) { $this->assertParameterArray($opt); $opt[self::BUCKET] = $bucket; $opt[self::OBJECT] = $object; $opt[self::METHOD] = 'PUT'; if ($content !== null && is_string($content)) { $opt['content'] = $content; } else { throw new BCS_Exception("Invalid object content, please check.", -1); } if (isset($opt['acl'])) { if (in_array($opt['acl'], self::$ACL_TYPES)) { self::set_header_into_opt("x-bs-acl", $opt['acl'], $opt); } else { throw new BCS_Exception("Invalid acl string, it should be acl_type", -1); } unset($opt['acl']); } if (isset($opt['filename'])) { self::set_header_into_opt("Content-Disposition", 'attachment; filename=' . $opt['filename'], $opt); } $response = $this->authenticate($opt); $this->log($response->isOK() ? "Create object[{$object}] success!" : "Create object[{$object}] failed! Response: [" . $response->body . "] Logid[" . $response->header["x-bs-request-id"] . "]", $opt); return $response; }
function file_writeBAE($file, $data) { global $_W; $file = str_replace(IA_ROOT.'/', '', $file); $file = $file[0] == '/' ? $file : '/'.$file; $pathinfo = pathinfo($file); $baiduBCS = new BaiduBCS($_W['config']['bae']['ak'], $_W['config']['bae']['sk']); $response = $baiduBCS->create_object_by_content($_W['config']['bae']['bucket'], $file, $data, array('acl' => BaiduBCS::BCS_SDK_ACL_TYPE_PUBLIC_READ)); if ($response->isOK()) { $baiduBCS->set_object_meta($_W['config']['bae']['bucket'], $file, array("Content-Type" => BCS_MimeTypes::get_mimetype($pathinfo['extension']))); $result['success'] = true; } }