作者 lyh

gx

... ... @@ -67,7 +67,7 @@ class AmazonS3Service
public function syncImageFiles($files)
{
$key = str_replace_url($files);
// try {
try {
$opts = [
'http' => [
'method' => 'GET',
... ... @@ -78,17 +78,20 @@ class AmazonS3Service
'verify_peer_name' => false
]
];
$file_handle = fopen($files, 'r', null, stream_context_create($opts));
$file_contents = fopen($files, 'r', null, stream_context_create($opts));
if ($file_contents === false) {
return '无法获取文件内容';
}
$result = $this->s3->putObject([
'Bucket' => $this->bucket,
'Key' => $key,
'Body' => $file_handle,
'Body' => $file_contents,
]);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($result, true) . PHP_EOL, FILE_APPEND);
return $result['ObjectURL'];
// } catch (AwsException $e) {
// @file_put_contents(storage_path('logs/lyh_error.log'), var_export('图片:'.$e->getMessage(), true) . PHP_EOL, FILE_APPEND);
// return '上传文件到S3时发生错误:' . $e->getMessage();
// }
} catch (AwsException $e) {
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('图片:'.$e->getMessage(), true) . PHP_EOL, FILE_APPEND);
return '上传文件到S3时发生错误:' . $e->getMessage();
}
}
}
... ...