|
...
|
...
|
@@ -66,11 +66,10 @@ class AmazonS3Service |
|
|
|
*/
|
|
|
|
public function syncImageFiles($files)
|
|
|
|
{
|
|
|
|
$location = '/tmp/'.basename($files);
|
|
|
|
$file_link = $this->fetchRemoteImage($files,$location);
|
|
|
|
$file_link = $this->fetchRemoteImage($files);
|
|
|
|
$key = str_replace_url($files);
|
|
|
|
try {
|
|
|
|
$file_content = file_get_contents($file_link);
|
|
|
|
$file_content = $file_link;
|
|
|
|
$result = $this->s3->putObject([
|
|
|
|
'Bucket' => $this->bucket,
|
|
|
|
'Key' => ltrim($key,'/'),
|
|
...
|
...
|
@@ -90,13 +89,13 @@ class AmazonS3Service |
|
|
|
* @method :post
|
|
|
|
* @time :2024/1/26 12:48
|
|
|
|
*/
|
|
|
|
public function fetchRemoteImage($url, $localPath) {
|
|
|
|
public function fetchRemoteImage($url) {
|
|
|
|
// 创建 cURL 句柄
|
|
|
|
$curl = curl_init();
|
|
|
|
// 设置 cURL 选项
|
|
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
// curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
// 执行请求并获取内容
|
|
|
|
$response = curl_exec($curl);
|
|
...
|
...
|
@@ -106,9 +105,7 @@ class AmazonS3Service |
|
|
|
// 处理错误
|
|
|
|
return 'cURL 错误:' . $error;
|
|
|
|
} else {
|
|
|
|
// 将内容保存到本地文件
|
|
|
|
file_put_contents($localPath, $response);
|
|
|
|
return $localPath;
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
// 关闭 cURL 句柄
|
|
|
|
curl_close($curl);
|
...
|
...
|
|