正在显示
1 个修改的文件
包含
20 行增加
和
17 行删除
| @@ -67,28 +67,31 @@ class AmazonS3Service | @@ -67,28 +67,31 @@ 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 { | ||
| 71 | - $opts = [ | ||
| 72 | - 'http' => [ | ||
| 73 | - 'method' => 'GET', | ||
| 74 | - 'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246' | ||
| 75 | - ], | ||
| 76 | - 'ssl' => [ | ||
| 77 | - 'verify_peer' => false, | ||
| 78 | - 'verify_peer_name' => false | ||
| 79 | - ] | ||
| 80 | - ]; | ||
| 81 | - $file_handle = fopen($files, 'r', null, stream_context_create($opts)); | 70 | + try { |
| 71 | + $opts = [ | ||
| 72 | + 'http' => [ | ||
| 73 | + 'method' => 'GET', | ||
| 74 | + 'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246' | ||
| 75 | + ], | ||
| 76 | + 'ssl' => [ | ||
| 77 | + 'verify_peer' => false, | ||
| 78 | + 'verify_peer_name' => false | ||
| 79 | + ] | ||
| 80 | + ]; | ||
| 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 | } |
-
请 注册 或 登录 后发表评论