1]); exit; } error_log("Downloaded file: " . strlen($fileContent) . " bytes"); // Получаем оригинальный путь файла из query параметра $s3Path = $_GET['s3Path'] ?? null; if (!$s3Path) { error_log("ERROR: s3Path not provided in callback URL!"); // Fallback: сохраняем во временную папку $s3Path = 'onlyoffice_saved/' . $key . '_' . date('Y-m-d_H-i-s') . '.docx'; error_log("Using fallback path: " . $s3Path); } else { error_log("Saving to original path: " . $s3Path); } // Инициализируем S3 клиент $s3Client = new Aws\S3\S3Client([ 'version' => 'latest', 'region' => 'ru-1', 'endpoint' => 'https://s3.twcstorage.ru', 'use_path_style_endpoint' => true, 'credentials' => [ 'key' => EnvLoader::getRequired('S3_ACCESS_KEY'), 'secret' => EnvLoader::getRequired('S3_SECRET_KEY') ], 'suppress_php_deprecation_warning' => true ]); $bucket = 'f9825c87-4e3558f6-f9b6-405c-ad3d-d1535c49b61c'; // Сохраняем в ОРИГИНАЛЬНОЕ место! $savedPath = $s3Path; // Определяем Content-Type на основе расширения файла $contentType = getContentType($savedPath); error_log("Content-Type: " . $contentType); $result = $s3Client->putObject([ 'Bucket' => $bucket, 'Key' => $savedPath, 'Body' => $fileContent, 'ContentType' => $contentType ]); error_log("File saved to S3: " . $savedPath); error_log("S3 Response: " . json_encode($result->toArray())); http_response_code(200); echo json_encode(['error' => 0]); exit; } catch (Exception $e) { error_log("Error saving file to S3: " . $e->getMessage()); http_response_code(500); echo json_encode(['error' => 1, 'message' => $e->getMessage()]); exit; } } // Другие статусы (1 = открыт, 4 = закрыт и т.д.) http_response_code(200); echo json_encode(['error' => 0]); exit; } // Для всех остальных запросов - 200 OK http_response_code(200); echo json_encode(['error' => 0]); /** * Определяет Content-Type на основе расширения файла */ function getContentType($filename) { $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $types = [ 'doc' => 'application/msword', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'xls' => 'application/vnd.ms-excel', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'ppt' => 'application/vnd.ms-powerpoint', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation' ]; return $types[$ext] ?? 'application/octet-stream'; } ?>