作者 lyh

gx

... ... @@ -67,7 +67,7 @@ class AmazonS3Service
public function syncImageFiles($files)
{
$key = str_replace_url($files);
try {
// try {
$opts = [
'http' => [
'method' => 'GET',
... ... @@ -80,14 +80,11 @@ class AmazonS3Service
];
$stream_context = stream_context_create($opts);
$file_handle = fopen($files, 'rb', null, $stream_context);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($file_handle.'1111111111', true) . PHP_EOL, FILE_APPEND);
if ($file_handle === false) {
@file_put_contents(storage_path('logs/lyh_error.log'), var_export(2222222, true) . PHP_EOL, FILE_APPEND);
return '无法打开文件';
}
$file_stats = fstat($file_handle);
$content_length = $file_stats['size'];
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($content_length, true) . PHP_EOL, FILE_APPEND);
$result = $this->s3->putObject([
'Bucket' => $this->bucket,
'Key' => $key,
... ... @@ -95,9 +92,8 @@ class AmazonS3Service
'ContentLength' => $content_length
]);
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) {
// return '上传文件到S3时发生错误:' . $e->getMessage();
// }
}
}
... ...