/** * 设置bucket的cors配置 * * @param OssClient $ossClient OssClient实例 * @param string $bucket 存储空间名称 * @return null */ function putBucketCors($ossClient, $bucket) { $corsConfig = new CorsConfig(); $rule = new CorsRule(); $rule->addAllowedHeader("x-oss-header"); $rule->addAllowedOrigin("http://www.b.com"); $rule->addAllowedMethod("POST"); $rule->setMaxAgeSeconds(10); $corsConfig->addRule($rule); try { $ossClient->putBucketCors($bucket, $corsConfig); } catch (OssException $e) { printf(__FUNCTION__ . ": FAILED\n"); printf($e->getMessage() . "\n"); return; } print __FUNCTION__ . ": OK" . "\n"; }