'ap-guangzhou', 'schema' => 'https', 'credentials' => [ 'secretId' => 'AKIDxOo34sUu892lWFoEnFVYS9A58D84pa8X', 'secretKey' => 'IMDwjS5Xpwtc9WiV7dz95rTvHUbYJtSv' ] ]); $localDir = __DIR__ . '/../server/public/uploads/goods'; $files = glob($localDir . '/*.jpg'); $map = []; foreach ($files as $file) { $filename = basename($file); $name = pathinfo($filename, PATHINFO_FILENAME); $cosKey = 'goods/' . $filename; $body = file_get_contents($file); try { $cosClient->putObject([ 'Bucket' => 'yjyf-1512102519', 'Key' => $cosKey, 'Body' => $body, 'ContentType' => 'image/jpeg' ]); $cosUrl = 'https://yjyf-1512102519.cos.ap-guangzhou.myqcloud.com/' . $cosKey; $map[$name] = [ 'cos' => $cosUrl, 'local' => '/uploads/goods/' . $filename, 'static' => '/static/goods/' . $filename ]; echo "Uploaded {$filename} to COS -> {$cosUrl}\n"; } catch (\Throwable $e) { echo "Error {$filename}: " . $e->getMessage() . "\n"; } } file_put_contents(__DIR__ . '/goods_images_map.json', json_encode($map, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); echo "All 31 real goods images synchronized to local, static and COS!\n";