20 * 1024 * 1024) { http_response_code(400); die('图片太大,请选择小于 20MB 的图片'); } $tmpPath = $file['tmp_name']; // Check if curl is available if (!function_exists('curl_init')) { http_response_code(500); die('服务器缺少 curl 扩展'); } // Forward to Node.js server $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => 'http://127.0.0.1:3001/photo-restore', CURLOPT_POST => true, CURLOPT_POSTFIELDS => ['image' => new CURLFile($tmpPath, $file['type'], $file['name'])], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 60, CURLOPT_CONNECTTIMEOUT => 5, ]); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); $error = curl_error($ch); curl_close($ch); if ($result === false || $httpCode !== 200) { http_response_code(500); die('处理失败: ' . ($error ?: '服务内部错误')); } // Return the processed image header('Content-Type: ' . ($contentType ?: 'image/jpeg')); header('Content-Length: ' . strlen($result)); header('Cache-Control: no-cache'); echo $result;