作者 lyh

gx

... ... @@ -165,7 +165,7 @@ class ProjectLogic extends BaseLogic
public function syncImageFile($location,$project_id){
if($location == 1){
CopyImageFile::dispatch(['project_id'=>$project_id]);
// CopyImageFile::dispatch(['project_id'=>$project_id]);
}
return $this->success();
}
... ...
... ... @@ -34,7 +34,6 @@ class CopyImageFileListener implements ShouldQueue
foreach ($imageList as $k => $v){
$rs = $amazonS3Service->syncImageFiles(getImageUrl($v['path']),$v['size']);
$imageModel->edit(['is_cos'=>0],['id'=>$v['id']]);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('图片:'.$rs, true) . PHP_EOL, FILE_APPEND);
}
}
... ... @@ -46,7 +45,6 @@ class CopyImageFileListener implements ShouldQueue
foreach ($fileList as $k => $v){
$amazonS3Service->syncImageFiles(getImageUrl($v['path']),$v['size']);
$fileList->edit(['is_cos'=>0],['id'=>$v['id']]);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('文件:'.$v['id'], true) . PHP_EOL, FILE_APPEND);
}
}
return true;
... ...
... ... @@ -64,30 +64,15 @@ class AmazonS3Service
* @method :post
* @time :2024/1/23 9:20
*/
public function syncImageFiles($files,$size)
public function syncImageFiles($files)
{
$key = str_replace_url($files);
// try {
$opts = [
'http' => [
'method' => 'GET',
'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'
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
];
$stream_context = stream_context_create($opts);
$file_handle = fopen($files, 'rb', null, $stream_context);
if ($file_handle === false) {
return '无法打开文件';
}
$file_content = file_get_contents($files);
$result = $this->s3->putObject([
'Bucket' => $this->bucket,
'Key' => $key,
'Body' => $file_handle,
'ContentLength' => $size
'Body' => $file_content,
]);
return $result['ObjectURL'];
// } catch (AwsException $e) {
... ...