<?php
echo "测试最终上传API...\n\n";

// 创建一个真正的MP4测试文件（使用FFmpeg创建一个简单的测试视频）
$tmpFile = tempnam(sys_get_temp_dir(), 'test_video_') . '.mp4';

// 使用命令创建测试视频
$command = 'ffmpeg -f lavfi -i color=c=red:s=1920x1080:r=25 -t 5 -c:v libx264 -pix_fmt yuv420p "' . $tmpFile . '"';
exec($command, $output, $returnVar);

if (!file_exists($tmpFile)) {
    echo "错误: 无法创建测试视频文件\n";
    exit(1);
}

echo "创建测试文件: $tmpFile\n";
echo "文件大小: " . filesize($tmpFile) . " bytes\n\n";

// 测试上传
$url = 'http://localhost/yangquan_wedding/api/upload_video_final.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);

$postData = [
    'video' => new CURLFile($tmpFile, 'video/mp4', 'test.mp4'),
    'video_type' => 'host',
    'video_name' => '测试视频'
];

curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

echo "HTTP状态码: $httpCode\n";
echo "CURL错误: $error\n";
echo "响应内容:\n";
echo $response . "\n";

// 清理
unlink($tmpFile);
?>