aws.rar
<?php
$root_path_aws = __DIR__;
require($root_path_aws . '/aws/aws-autoloader.php');
/**
* 图片文件推送到Aws S3
*
* @author: lianghuiju@chuchujie.com
*
* @access: public
* @params: string $key 照片名字
* @params: string $filePath 文件路径
*/
function upload_image_qiniu($filePath, $key) {
$APPPATH = __DIR__;
$sharedConfig = [
'version' => '2006-03-01',
'region' => 'cn-north-1',
'credentials' => [
'key' => '自己的key',
'secret' => '自己注册就有的'
],
'http' => [
'verify' => $APPPATH . '/aws/cacert.pem',
]
];
$Aws = new Aws\Sdk($sharedConfig);
$S3Client = $Aws->createS3();
$result = $S3Client->putObject([
'Bucket' => "culiu.cdn",
'Key' => 'pintuan/' . $key,
'SourceFile' => $filePath,
'ACL' => 'public-read',
]);
if ($result['ObjectURL']) {
return true;
} else {
return false;
}
}
/**
* 图片从Aws S3 删除
* @param $name 图片名称
* @return bool
* author : lianghuiju@jiayuan.com
* function_name : delete_image_qiniu
* description :
*/
function delete_image_qiniu($name) {
$APPPATH = __DIR__ . '/aws';
$sharedConfig = [
'version' => '2006-03-01',
'region' => 'cn-north-1',
'credentials' => [
'key' => '自己的key',
'secret' => '自己注册就有的'
],
'http' => [
'verify' => $APPPATH . '/cacert.pem',
]
];
$key = 'pintuan/' . $name;
$Aws = new Aws\Sdk($sharedConfig);
$S3Client = $Aws->createS3();
$result = $S3Client->deleteObject([
'Bucket' => "culiu.cdn",
'Key' => $key,
]);
if ($result) {
return true;
} else {
return false;
}
}
神回复
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。