正在显示
1 个修改的文件
包含
10 行增加
和
7 行删除
| @@ -67,7 +67,7 @@ class AmazonS3Service | @@ -67,7 +67,7 @@ class AmazonS3Service | ||
| 67 | public function syncImageFiles($files) | 67 | public function syncImageFiles($files) |
| 68 | { | 68 | { |
| 69 | $key = str_replace_url($files); | 69 | $key = str_replace_url($files); |
| 70 | -// try { | 70 | + try { |
| 71 | $opts = [ | 71 | $opts = [ |
| 72 | 'http' => [ | 72 | 'http' => [ |
| 73 | 'method' => 'GET', | 73 | 'method' => 'GET', |
| @@ -78,17 +78,20 @@ class AmazonS3Service | @@ -78,17 +78,20 @@ class AmazonS3Service | ||
| 78 | 'verify_peer_name' => false | 78 | 'verify_peer_name' => false |
| 79 | ] | 79 | ] |
| 80 | ]; | 80 | ]; |
| 81 | - $file_handle = fopen($files, 'r', null, stream_context_create($opts)); | 81 | + $file_contents = fopen($files, 'r', null, stream_context_create($opts)); |
| 82 | + if ($file_contents === false) { | ||
| 83 | + return '无法获取文件内容'; | ||
| 84 | + } | ||
| 82 | $result = $this->s3->putObject([ | 85 | $result = $this->s3->putObject([ |
| 83 | 'Bucket' => $this->bucket, | 86 | 'Bucket' => $this->bucket, |
| 84 | 'Key' => $key, | 87 | 'Key' => $key, |
| 85 | - 'Body' => $file_handle, | 88 | + 'Body' => $file_contents, |
| 86 | ]); | 89 | ]); |
| 87 | @file_put_contents(storage_path('logs/lyh_error.log'), var_export($result, true) . PHP_EOL, FILE_APPEND); | 90 | @file_put_contents(storage_path('logs/lyh_error.log'), var_export($result, true) . PHP_EOL, FILE_APPEND); |
| 88 | return $result['ObjectURL']; | 91 | return $result['ObjectURL']; |
| 89 | -// } catch (AwsException $e) { | ||
| 90 | -// @file_put_contents(storage_path('logs/lyh_error.log'), var_export('图片:'.$e->getMessage(), true) . PHP_EOL, FILE_APPEND); | ||
| 91 | -// return '上传文件到S3时发生错误:' . $e->getMessage(); | ||
| 92 | -// } | 92 | + } catch (AwsException $e) { |
| 93 | + @file_put_contents(storage_path('logs/lyh_error.log'), var_export('图片:'.$e->getMessage(), true) . PHP_EOL, FILE_APPEND); | ||
| 94 | + return '上传文件到S3时发生错误:' . $e->getMessage(); | ||
| 95 | + } | ||
| 93 | } | 96 | } |
| 94 | } | 97 | } |
-
请 注册 或 登录 后发表评论