作者 lyh

gx

... ... @@ -80,18 +80,20 @@ 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, 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,
'Body' => $file_handle,
'ContentLength' => $content_length
]);
@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);
... ...